Switch statement is very useful for creating a calculator which performs following operations: Addition, Substraction, Multiplication, Division and Modulus
#include<stdio.h>
#include<conio.h>
void main()
{
char a,b,c,d;
clrscr();
printf("Enter the values of a and b:");
scanf("%d%d" ,&a,&b);
printf(" Enter your choice between 1 to 5 /n");
{
case 1;
c=a+b;
printf(" Addition=%d", c);
break:
case 2;
c=a-b;
printf(" Substraction=%d" , c);
break:
case 3;
c=a*b;
printf(" Multiplication=%d", c);
break:
case 4;
c=a/b;
printf(" Divide=%d", c);
break:
case 5;
c=a%b;
printf(" Remainder=%d",c );
break:
default:
printf(" Invalid Result");
break:
}
Output1:
Enter the values of a and b:
3
5
Enter your choice between 1 to 5
1
Addition=8
Output2:
Enter the values of a and b:
5
5
Enter your choice between 1 to 5
3
Multiplication=25
Output3:
Enter the values of a and b:
50
10
Enter your choice between 1 to 5
4
Divide=5
Output4:
Enter the values of a and b:
8
2
Enter your choice between 1 to 5
5
Remainder=0
Output5:
Enter the values of a and b:
3
5
Enter your choice between 1 to 5
9
Invalid Result
0 Response to "C Program: Make a Calculator by using switch Statement"
Post a Comment