write a program to perform different mathematical operators by using switch case
Answers
Explanation:
#include<stdio.h>
#include<conio.h>
int main()
{
int a,b;
int op;
printf(" 1.Addition\n 2.Subtraction\n 3.Multiplication\n 4.Division\n");
printf("Enter the values of a & b: ");
scanf("%d %d",&a,&b);
printf("Enter your Choice : ");
scanf("%d",&op);
switch(op)
{
case 1 :
printf("Sum of %d and %d is : %d",a,b,a+b);
break;
case 2 :
printf("Difference of %d and %d is : %d",a,b,a-b);
break;
case 3 :
printf("Multiplication of %d and %d is : %d",a,b,a*b);
break;
case 4 :
printf("Division of Two Numbers is %d : ",a/b);
break;
default :
printf(" Enter Your Correct Choice.");
break;
}
return 0;
}
The above program can write in an another way using operators in switch case
C Program to Perform Arithmetic Operations Using Switch
Flowchart for the same program
Flowchart to Perform Arithmetic Operations Using Switch
Output for Program:
1.Addition
2.Subtraction
3.Multiplication
4.Division
Enter the values of a & b: 20 15
Enter your Choice : 1
Sum of 20 and 15 is : 35