Skip to content
Home » C Programs » C Program for Calculator Using Switch Case

C Program for Calculator Using Switch Case

Basic c program for calculator using switch case. 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

Switch Case in C

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. Using this method we can execute the program to c program for calculator using switch case

Return Statement in C

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.

C Program for Calculator Using Switch Case

#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