Create a menu driven program.
#include <stdio.h>
#include <conio.h>
void main ( )
{
int cho, no, no1, co, md, fl, s;
unsigned long fact;
clrscr ( );
while ( 1 )
{
printf ("\n\t\t\tMENU");
printf ("\n\t\t\t====");
printf ("\n\n\t\t 1. FACTORIAL\n");
printf ("\t\t 2. PRIME \n");
printf ("\t\t 3. ARMSTRONG \n");
printf ("\t\t 4. ODD / EVEN \n");
printf ("\t\t 5. EXIT \n");
printf ("\n\t\t Your Choice ?"); scanf ("%d", &cho);
switch ( cho )
{
case 1:
fact = 1;
printf ("\n\t Enter the number.......:"); scanf ("%d",&no);
for ( co =1; co <= no; co++ )
{
fact = fact * co;
}
printf ("\n\t FACTORIAL = %ld", fact);
break;
case 2:
fl = 0;
printf ("\n\t Enter a number...........:"); scanf ("%d", &no);
for ( co = 2; co < no; co++ )
{
md = no % co;
if ( md == 0 )
{
fl = 1;
break;
}
}
if ( fl == 0 )
printf ("\n\t It is a Prime number");
else
printf ("\n\t It is not a Prime number");
break;
case 3:
s = 0;
printf ("\n\t Enter a number.........:"); scanf ("%d",&no);
no1 = no;
while ( no > 0 )
{
md = no % 10;
no = no /10;
s = s + ( md * md * md );
}
if ( no1 == s )
printf ("\n\t Number = %d is an Armstrong number", no1);
else
printf ("\n\t Number = %d is not an Armstrong number",
no1);
break;
case 4:
printf ("\n\t Enter a number.........:"); scanf ("%d",&no);
if ( no % 2 == 0 )
printf ("\n\t Even number");
else
printf ("\n\t Odd number");
break;
case 5:
exit ( );
default:
printf("\n WRONG CHOICE.");
}
getch ( );
clrscr ( );
}
}
Click here to contact us
No comments:
Post a Comment