Problem
Write a menu driven program using switch case statement (without functions) that has the following options:- Factorial of a number
- Prime or not
- Odd or even
- Power ( x raise to power y)
- Exit
Solution - Code
#include<stdio.h>#include<conio.h>
#include<stdlib.h>
main()
{
int c,n,b,i,j,g;
printf("Select one :\n 1. factorial.\n2. prime nmber:\n3. even or odd:\n4. exit.\n Enter choice:");
scanf("%d",&c);
switch(c)
{
case 1:
printf("enter no.:");
scanf("%d",&n);
b=1;
for(i=n;i>0;i--)
b=b*i;
printf("factorial is %d",b);
system("pause");
break;
case 2 :
printf("Enter no.:");
scanf("%d",&j);
if(j%2==0)
{
printf("it is not a prime numbr.\n");
}
else
printf("it is a prime number.\n");
system("pause");
break;
case 3 :
printf("enter the :");
scanf("%d",&g);
if(g%2==0)
printf("it is an even number.\n");
else
printf("not an even number\n");
system("pause");
break;
case 4 :
exit(0);
}
system("pause");
}
For prime number the program is wrong
ReplyDeleteThanks For Your Kind Response. Will Definitely Look Into It ASAP.
Delete