Menu driven program using switch case in C
switch case - Question 5
In this question, we will see how to create a menu-driven program in C using the switch case statement. To know more about switch case statement click on the switch case statement lesson.
Q5) Write a menu-driven program using the switch case statement in C to check whether a number is:
- Even number or Odd number
- Two digit positive number or not
- Multiple of 5 or not
Program
#include <stdio.h>
#include <conio.h>
int main()
{
int c,n;
printf("1 Even number or Odd number\n");
printf("2 Two digit positive number or not\n");
printf("3 Multiple of 5 or not\n");
printf("Enter your choice: ");
scanf("%d",&c);
switch(c)
{
case 1:
printf("Enter a number ");
scanf("%d",&n);
if(n%2==0)
{
printf("Even Number");
}
else
{
printf("Odd Number");
}
break;
case 2:
printf("Enter a number ");
scanf("%d",&n);
if(n>=10 && n<100)
{
printf("Two digit positive number");
}
else
{
printf("Not two digit positive number");
}
break;
case 3:
printf("Enter a number ");
scanf("%d",&n);
if(n%5==0)
{
printf("Multiple of 5");
}
else
{
printf("Not multiple of 5");
}
break;
default:
printf("Invalid Choice");
}
return 0;
}
Output
1 Even number or Odd number 2 Two digit positive number or not 3 Multiple of 5 or not Enter your choice: 2 Enter a number 58 Two digit positive number