You are on page 1of 2

# Write the following menu-based program using function statement:

1-Factorial
2-Even/Odd
3-Calculate exponent
4-exit
============================================
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
long int factorial(long int);
int iseven(int);
void main()
{
clrscr();
int op,counter=1;
while(op!=3)
{
cout<<"\n\n\nPress 1 for Factorial";
cout<<"\nPress 2 for Even/Odd";
cout<<"\nPress 3 to Exit";
cin>>op;
switch(op)
{
case 1:
{
int fact,no;
cout<<"\n\t\t\tFACTORIAL";
cout<<"\n\n\tEnter any number ";
cin>>no;
fact=factorial(no);
cout<<"\n\t\tThe Factorial of "<<no<<" = "<<fact;
break;
}
case 2:
{
int num,even;
cout<<"\n\t\t\tEVEN/ODD";
cout<<"\n\n\tEnter any number ";
cin>>num;
even=iseven(num);
if(even=='y')
cout<<"\n\n\t\tThe number is Even";
else
cout<<"\n\n\t\tThe number is Odd";
break;
case 3:
{
exit(0);
break;
}
default:
cout<<"\n\t\tInvalid Option";
counter++;
}
}
getch();
}
}
long int factorial(long int num)
{
int fact=1;
for(int a=1;a<=num;a++)
{
fact=fact*a;
}
return(fact);
}
int iseven(int no)
{
int even;
if(no%2==0)
even='y';
else
even='n';
return(even);
}

http://www.ravianeducation.blogspot.com
FARHAN: 03008855006