Browse Source

switchcasemenuproject

Write a menu driven program which has following options
a) Factorial of a number
b) Prime or not
c) Odd or even
d) Exit
pull/673/head
subha-code GitHub 5 years ago
parent
commit
960c274e49
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 49 additions and 0 deletions
  1. +49
    -0
      menuproject

+ 49
- 0
menuproject View File

@@ -0,0 +1,49 @@
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
main()
{int ch, i,n,fact=1, c = 0,a;
while(1) // condition is always true, thus an infinite loop
{
printf("\n1. Factorial of a number");
printf("\n2. Prime or not");
printf("\n3. Odd or even ");
printf("\n4. Exit");
printf("\n\nEnter your choice");
scanf("%d",&ch);
switch(ch)
{ case 1:printf("\n Enter a number :");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact=fact*i;
}
printf("\n The factorial of %d is %d ",n,fact);
break; //it is used to move control out of switch body
case 2:printf("Enter any number n:");
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
if (n % i == 0)
{
c++;
}
}
if (c == 2) {
printf("%d is a Prime number",n);
}
else {
printf("%d is not a Prime number",n);
break; //it is used to move control out of switch body
case 3:printf("\n Enter a number :");
scanf("%d",&a);
if(a%2==0)
printf("\nthe number %d is even ",a);
else
printf("\n The number %d is odd ",a);
break; //it is used to move control out of switch body
case 4:exit(0);
default:printf("Invalid Entry")
}
}
}

Loading…
Cancel
Save