How to write Menu Driven program using Switch case in C
#include<stdio.h>
#include<conio.h>
#include<Process.h>
main()
{
int choice,num,i;
long int fact;
printf("\n1.Factorial
number");
printf("\n2.Prime\n");
printf("\n3.Odd or
even\n");
printf("\n4. Multiplication
table");
printf("\n5. Exit\n");
printf("\nEnter
your choice (1/2/3/4/5):-");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Enter
number=");
scanf("%d",&num);
fact=1;
for(i=1;i<num;i++)
fact=fact*i;
printf("Functional
no=%|d",fact);
break;
case 2:
printf("Enter
number =");
scanf("%d",&num);
for(i=2;i<num;i++)
{
if(num%i==0)
{
printf("\nNot
Prime");
break;
}
}
if(i==num)
printf("\n
Prime number");
break;
case 3:
printf("Enter
number=");
scanf("%d",&num);
if(num%2==0)
printf("\n
even number");
else
printf("\n
odd number");
break;
case 4:
printf("Enter
no=");
scanf("%d",&num);
for(i=1;i<=10;i++)
{
int
mult=num*i;
printf("\t%dX%d=%d\n",num,i,mult);
}
break;
case 5:
exit(0);
default:
printf("You
are not allowed to type other");
exit(0);
}
getch();
}
No comments:
Post a Comment