1. Factorial of a number.
2. Prime or not
3. Odd or even
4. Exit
Once a menu item is selected the appropriate action should be taken and once this action is finished, the menu should reappear. Unless the user selects the ‘Exit’ option the program should continue to work.
#include<stdio.h> #include<conio.h> #include<stdlib.h> void main() { int choice, num, i; unsigned long int fact; while(1) { printf("1.Factorial : \n"); printf("2.Prime : \n"); printf("3.Odd/Even : \n"); printf("4.Exit\n"); printf("\nYour choice :? "); scanf("%d",&choice); switch(choice) { case 1: printf("\nEnter Number :"); scanf("%d",&num); fact = 1; for(i=1;i<=num;i++) fact = fact * i; printf("\n Factorial value = %lu\n",fact); break; // Takes control out of switch case 2: printf("\n Enter number :"); scanf("%d",&num); for(i=2;i<num;i++) { if(num%i== 0) { printf("\n Not a prime Number.\n"); break; //Takes control out of for loop } } if(i==num) printf("\n Prime Number.\n"); break; //Takes control out of switch case 3: printf("\nEnter Number:"); scanf("%d",&num); if(num %2==0) printf("\n Even Number.\n"); else printf("\nOdd Number.\n"); break; //Takes control out of switch case 4: exit(0); //Terminates program execution } } getch(); }