// Operator as case in switch case
#include<stdio.h>
int main()
{
char op;
float num1,num2,res;
printf("Enter first number:>>\n");
scanf("%f",&num1);
printf("Enter second number:>>\n");
scanf("%f",&num2);
printf("Operation(+,-,*,/) \n");
scanf("%c",&op);
switch(op)
{
case '+':
{
res=num1+num2;
break;
}
case '-':
{
res=num1-num2;
break;
}
case '*':
{
res=num1*num2;
break;
}
case '/':
{
res=num1/num2;
break;
}
default:
{
printf("Invalid choice...");
}
}
printf("Result::%f",res);
return 0;
}
Note: Click on copy button to copy the given code and you can paste it in any online compiler to see the result, IF YOU ARE A MOBILE USER THEN DOWNLOAD "CODING C"(Free App) COMPILER FROM GOOGLE PLAY STORE.