Experiments-4

Write a menu driven program which has following options:
1. Factorial of a number.
2. Prime or not
3. Odd or even
4. Exit



#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num , ch , b=0,fact=1;
cout<<"To check wether number is Prime Press 1"<<endl;
cout<<"To check wether number is Even or Odd Press 2"<<endl;
cout<<"To get the factorial of a number press 3"<<endl;
cout<<"To exit press any other key"<<endl;
cout<<"Enter your choice: ";
cin>>ch;
if(ch==1){cout<<"Enter the number: ";
cin>>num;
for(int i = 1;i<num;i++)
{
if(b%i==0)
{
b=1;
}
}
if(b==1)
{
cout<<"The number is Prime";
}
Else
{
cout<<"The number is not Prime";
}
}
if(ch==2)
{
cout<<"Enter the number: ";
cin>>num;
if(num%2==0)
{
cout<<"The number is Even";
}
Else
{
cout<<"The number is Odd";
}
}
if(ch==3)
{
cout<<"Enter the number: ";
cin>>num;
for(int i = 1;i<=num;i++)
{
fact = fact*i;
}
cout<<"The factorial is: "<<fact;
}
getch();
}



No comments:

Post a Comment

Note: only a member of this blog may post a comment.