Write a menu based program in C addition, subtraction, multiplication, division using if else.
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
int a,b,r,ch;
clrscr();
printf("\tMENU\n");
printf("1.Addition\n") ;
printf("2.Subtraction\n");
printf("3.Multiplication\n") ;
printf("4.Division\n");
printf("5.Exit\n");
printf("Enter choice number:-\n");
scanf("%d",&ch) ;
if(ch<1||ch>5)
printf("Wrong choice");
else
{
if(ch==1)
{
printf("Enter two no.:-");
scanf("%d%d",&a,&b);
r=a+b;
printf("Sum=%d",r);
}
if(ch==2)
{
printf("Enter two no.:-");
scanf("%d%d",&a,&b);
r=a-b;
printf("Sub=%d",r);
}
if(ch==3)
{
printf("Enter two no.:-");
scanf("%d%d",&a,&b) ;
r=a*b;
printf("Mul=%d",r);
}
if(ch==4)
{
printf("Enter two no.:-");
scanf("%d%d",&a,&b);
r=a/b;
printf("Div=%d",r) ;
}
if(ch==5)
exit(0);
}
getch();
}
0 Comments