39. C Program to Perform Arithmetic calculations using switch case.
How does this program work?
- In this program your going to learn about how to use switch case for arthematic operations in C-Language.
Here is the code
#include <stdio.h>
int main(void)
{
int a, b,g;
float r;
printf("Enter two numbers :\n ");
scanf("%d%d", &a, &b);
printf("1 -> Addition\n");
printf("2 ->Subtraction\n");
printf("3 -> multiplication\n");
printf("4 ->Divison\n");
printf("Choose an option \n");
scanf("%d",&g);
switch(g)
{
case 1:
r = a+b;
printf("Addition = %.1f",r);
break;
case 2:
r = a-b;
printf("Subtraction= %.2f",r);
break;
case 3:
r = a*b;
printf("Multiplication= %.3f",r);
break;
case 4:
r = a/b;
printf("Divison= %.2f", r);
break;
default:
printf("Invalid option\n");
}
return 0;
}