Write a menu-driven program in C using a switch case to calculate Addition, Subtraction, Multiplication, and Division.
--------------------------
menu
1. add two number
2. substract two number
3. multiply two number
4. divide two number
5. break
----------------------------
enter your choice:
#include<stdio.h>
int main()
{
int a,b,choice;
float c,d;
while(choice!=5)
{
printf("\n--------------------------");
printf("\n menu");
printf("\n1.add two number");
printf("\n2.substract two number");
printf("\n3.multiply two number");
printf("\n4.divide two number");
printf("\n5.break");
printf("\n----------------------------");
printf("\nenter your choice:");
scanf("%d",&choice);
switch(choice)
{
case(1):
printf("\nenter two numbers");
scanf("%d%d",&a,&b);
printf("\naddition of two number is %d",a+b);
break;
case(2):
printf("\nenter two numbers");
scanf("%d%d",&a,&b);
printf("\nsubstraction of two number is %d",a-b);
break;
case(3):
printf("\nenter two numbers");
scanf("%d%d",&a,&b);
printf("\nmultiplication of two number is %d",a*b);
break;
case(4):
printf("\nenter two numbers");
scanf("%f%f",&c,&d);
printf("\ndivision of two number is %f",c/d);
break;
case(5):
break;
default:
printf("\nwrong choice");
break;
}
}
return 0;
}
-------------------------- menu 1. add two number 2. substract two number 3. multiply two number 4. divide two number 5. break ---------------------------- enter your choice:1 enter two numbers:10 20 addition of two number is 30 -------------------------- menu 1. add two number 2. substract two number 3. multiply two number 4. divide two number 5. break ---------------------------- enter your choice:2 enter two numbers:20 5 substraction of two number is 15 -------------------------- menu 1. add two number 2. substract two number 3. multiply two number 4. divide two number 5. break ---------------------------- enter your choice:3 enter two numbers:4 3 multiplication of two number is 12 -------------------------- menu 1. add two number 2. substract two number 3. multiply two number 4. divide two number 5. break ---------------------------- enter your choice:4 enter two numbers:10 5 division of two number is 2.000000 -------------------------- menu 1. add two number 2. substract two number 3. multiply two number 4. divide two number 5. break ----------------------------