C program for implementing switch case

Switch-case statements can be a kind of alternative for if-else statements in some cases. Switch-case also controls the selection mechanism using a variable or constants.

This C Program performs various mathematical operations on two integers using switch case.

#include<stdio.h>
#include<math.h>
int main(){
int n,a,b;
printf("enter a");
scanf("%d",&a);
printf("enter b");
scanf("%d",&b);
printf("\n 1.addition \n 2.subtraction \n 3.multiplicaton \n 4. division");
printf("\n enter your choice");
scanf("%d",&n);
switch(n){
case 1:
printf("%d",a+b);
break;

case 2:
printf("%d",a-b);
break;
case 3:
printf("%d",a*b);
break;
case 4:
printf("%d",(float)a/b);
break;
}

}

 

Output