C program to create a calculator using a switch statement

In this post, we will know about code for c program to create a calculator using a switch statement.

Code for C program to create a calculator using a switch statement

#include <stdio.h>
#include<conio.h>
int main()
{
char ch;
int a,b,result;
printf("Enter the Operands (+, -, *, /):");
scanf("%c", &ch);
printf("Enter two numbers:\n");
scanf("%d %d", &a, &b);
switch (ch)
{
case '+':
result=a+b;
break;
case '-':
result=a-b;
break;
case '*':
result=a*b;
break;
case '/':
result=a/b;
break;
}
printf ("Result=%d", result);
return 0;
}

Output:

Enter the Operands (+, -, *, /): +
Enter two numbers:
5 9
Result=14

Read: C program to check whether a given alphabet is a vowel or consonant


If You Like This Page Then Make Sure To Follow Us on Facebook, G News and Subscribe Our YouTube Channel. We will provide you updates daily.
Shares
facebook sharing button Share
twitter sharing button Tweet
whatsapp sharing button Share
telegram sharing button Share
pinterest sharing button Pin

Leave a Comment