Program # 19: Program to perform multiple operations
//Program to select an operation from list and display its results (Level - Medium)
#include <iostream.h>
#include <conio.h> #include <complex.h>
#include <conio.h> #include <complex.h>
void main ()
{
clrscr();
int i,n,x,p,b,res,count;
cout<<"1. Factorial"<<endl;
cout<<"2. OddƒEven "<<endl;
cout<<"3. Prime"<<endl;
cout<<"1. Factorial"<<endl;
cout<<"2. OddƒEven "<<endl;
cout<<"3. Prime"<<endl;
cout<<"4. Raise to power"<<endl;
cout<<"5. Square root"<<endl; cout<<"Press the number of your choice ";
cin >> n;
cout<<"5. Square root"<<endl; cout<<"Press the number of your choice ";
cin >> n;
res = 1;
count = 0;
switch (n)
switch (n)
{
case 1:
cout<<"Enter
any number = ";
cin >> n;
for(i=1;i<=n;i++)
res = res*i;
cout<<"The
factorial of given number is = "<<res<<endl;
break;
case 2:
case 2:
cout<<"Enter
any number = ";
cin >> n;
if(n%2 == 0)
cout<<"The
number is even ";
else
cout<<"The number is odd ";
else
cout<<"The number is odd ";
break ;
case 3:
case 3:
cout<<"Enter
any number = ";
cin >> n;
cin >> n;
for (i=1;i<=n;i++)
if(n%i==0)
count= count+1;
if(count==2)
cout<<"The
number is prime
";
else
cout<<"The number is not prime";
break;
case 4:
cout<<"Enter the base of number = ";
cin >> b;
cout<<"Enter the power of number = ";
cin >> p;
else
cout<<"The number is not prime";
break;
case 4:
cout<<"Enter the base of number = ";
cin >> b;
cout<<"Enter the power of number = ";
cin >> p;
for (i=1;i<=p;i++)
res = res*b;
cout<<"The raise to power of number = <<res;
break;
break;
case 5:
cout<<"Enter
any number = ";
cin >> n;
cin >> n;
float res =
sqrt(n);
cout<<"The
square root of the number is = "<<res;
break; default:
cout<<"Press
the number in the above series";
}
getch ();
}
0 Comments