Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- while (true)
- {
- int num;
- cout << "Enter 1 for Hello World : \nEnter 2 for Calculation : \nEnter 3 for Swapping of 2 numbers : \nEnter 4 for Swapping of 3 numbers : \nEnter 5 for Fibonacci series : \nEnter 6 for Square of number : \nEnter 7 for Area of triangle : \nEnter 8 for Area of circle : \nEnter 9 for Simple interest : \nEnter 10 for checking Leap year or not : \nEnter 11 for Check character vowel or not : \nEnter 12 for Table of any number :- \nEnter 13 for Prime number :- \n\nEnter any number from above stated = ";
- cin >> num;
- switch (num)
- {
- case 1:
- cout << "Hello World";
- break;
- case 2:
- {
- int a1, a2, val;
- cout << "Enter any two numbers = ";
- cin >> a1 >> a2;
- cout << "Enter 1 for Addition :- \nEnter 2 for Subtraction :- \nEnter 3 for Multiplication :- \nEnter 4 for Division :- \nEnter 5 for Modulus (Remainder) :- \nEnter 6 for All Calculation :- \n\nPlease Enter = ";
- cin >> val;
- switch (val)
- {
- case 1:
- cout << "\nAddition = " << a1 + a2;
- break;
- case 2:
- cout << "\nSubtraction = " << a1 - a2;
- break;
- case 3:
- cout << "\nMultiplication = " << a1 * a2;
- break;
- case 4:
- if (a2 != 0)
- cout << "\nDivision = " << a1 / a2;
- else
- cout << "\nDivision by zero is not allowed";
- break;
- case 5:
- if (a2 != 0)
- cout << "\nModulus (Remainder) = " << a1 % a2;
- else
- cout << "\nModulus (Remainder) by zero is not allowed";
- break;
- case 6:
- cout << "\nAddition = " << a1 + a2;
- cout << "\nSubtraction = " << a1 - a2;
- cout << "\nMultiplication = " << a1 * a2;
- if (a2 != 0)
- cout << "\nDivision = " << a1 / a2;
- else
- cout << "\nDivision by zero is not allowed";
- if (a2 != 0)
- cout << "\nModulus (Remainder) = " << a1 % a2;
- else
- cout << "\nModulus (Remainder) by zero is not allowed";
- break;
- default:
- cout << "Invalid number";
- break;
- }
- }
- break;
- case 3:
- {
- int b1, b2, choice;
- cout << "\nEnter 1 for Swapping with a third variable :- \nEnter 2 for Swapping without a third variable :- \n\nNow Enter here= ";
- cin >> choice;
- int b3;
- switch (choice)
- {
- case 1:
- cout << "Enter the value of a and b = ";
- cin >> b1 >> b2;
- b3 = b1;
- b1 = b2;
- b2 = b3;
- cout << "a=" << b1 << "\nb=" << b2;
- break;
- case 2:
- cout << "Enter the value of a and b = ";
- cin >> b1 >> b2;
- b1 = b1 + b2;
- b2 = b1 - b2;
- b1 = b1 - b2;
- cout << "a=" << b1 << "\nb=" << b2;
- break;
- default:
- cout << "Invalid choice";
- break;
- }
- }
- break;
- case 4:
- {
- int n1, n2, n3;
- cout << "Enter the value of a, b, and c = ";
- cin >> n1 >> n2 >> n3;
- int n4 = n1;
- n1 = n2;
- n2 = n3;
- n3 = n4;
- cout << "a=" << n1 << "\nb=" << n2 << "\nc=" << n3;
- }
- break;
- case 5:
- {
- int d1 = 0, d2 = 1, d3, d4, d5;
- cout << "Enter the number of values to be printed for the Fibonacci series = ";
- cin >> d5;
- cout << "Fibonacci Series :-" << endl;
- cout << d1 << endl
- << d2;
- for (d4 = 3; d4 <= d5; d4++)
- {
- d3 = d1 + d2;
- d1 = d2;
- d2 = d3;
- cout << endl << d3;
- }
- }
- break;
- case 6:
- {
- int e;
- cout << "Enter any number you want the square of = ";
- cin >> e;
- cout << "Square of " << e << " = " << e * e;
- }
- break;
- case 7:
- {
- float base, height, area1;
- cout << "Enter the value of base and height = ";
- cin >> base >> height;
- area1 = (base * height) / 2;
- cout << "Area of Triangle = " << area1;
- }
- break;
- case 8:
- {
- float area, radius;
- cout << "Enter the value of the radius = ";
- cin >> radius;
- area = (22 * radius * radius) / 7;
- cout << "Area of Circle = " << area;
- }
- break;
- case 9:
- {
- float p, r, t, si;
- cout << "Enter the value of P, R, and T = ";
- cin >> p >> r >> t;
- si = (p * r * t) / 100;
- cout << "Simple Interest = " << si;
- }
- break;
- case 10:
- {
- int year;
- cout << "Enter any Year = ";
- cin >> year;
- if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
- cout << year << " is a Leap Year";
- else
- cout << year << " is not a Leap Year";
- }
- break;
- case 11:
- {
- char ch;
- cout << "Enter any character = ";
- cin >> ch;
- switch (ch)
- {
- case 'a':
- case 'e':
- case 'i':
- case 'o':
- case 'u':
- case 'A':
- case 'E':
- case 'I':
- case 'O':
- case 'U':
- cout << " " << ch << " is a Vowel";
- break;
- default:
- cout << " " << ch << " is not a Vowel";
- break;
- }
- }
- break;
- case 12:
- {
- int n;
- cout << "Enter any number you want the table of = ";
- cin >> n;
- for (int i = 1; i <= 10; i++)
- {
- cout << n << "*" << i << "=" << n * i << endl;
- }
- }
- break;
- case 13:
- {
- int n;
- cout << "Enter any number = ";
- cin >> n;
- if(n<=1){
- cout<<"Not prime \n";
- break;
- }
- bool check = true;
- for(int i=2 ; i<= (n/2) ; i++){
- if(n%i==0){
- check = false;
- break;
- }
- }
- if(check){
- cout<<n<<" is prime\n";
- }
- else{
- cout<<n<<" is not prime\n";
- }
- }
- break;
- default:
- cout << "Please enter a valid number";
- break;
- }
- cout << "\nDo you want to continue? (y/n): ";
- char choice;
- cin >> choice;
- if (choice != 'y' && choice != 'Y')
- break;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment