C program to print calculator using switch statement

C program to print calculator using switch statement. Simple calculator program in C programming language. This program will execute perform basic task like add, sub, mul and div. To run and execute the basic operation can be done in the simple calculator program in c for beginners

#include<stdio.h> 
int main()
{ 
int a, b, total;
char op; 
printf("Enter the number");
scanf("%d%c%d", &a, &op, &b);
switch(op)
{
case '+':
total = a + b;
break;
case '-':
total = a - b;
break;
case '*':
total = a * b;
break;
case '/':
total = a / b;
break; 
}
printf("total = %d", total);
return 0; 
} 

 

Output

Enter the number

56+44

total = 100

What is switch case in c program

Long if statements that compare a variable to many integral values can be replaced with switch case statements. A multiway branch statement is the switch statement. It makes it simple to route execution to various portions of code based on the expression’s value.

What is return statement in c program

A return statement marks the end of a function’s execution and hands control back to the calling function. The calling function continues execution at the place where the call was made. A return statement can give the calling function a value.