Computer Science, asked by nkpradeepkumar28, 2 months ago

Write a C program to design a calculator with basic operations(+,_*,/,%) using
switch case.
Sample testcases
Input 1
/
8
3
Output 1
2​

Answers

Answered by abhishekkanand9
0

Answer:

include<stdio.h>

int main()

{

char ch;

int num1,num2;

printf("Choose the operator(+,-,*,/,%%): ");

scanf("%c",&ch);

printf("Enter two numbers: ");

scanf("%d %d",&num1,&num2);

switch(ch)

{

case '+':

printf("%d + %d =\t%d\n",num1,num2,num1+num2);

break;

case '-':

printf("%d - %d =\t%d\n",num1,num2,num1-num2);

break;

case '*':

printf("%d * %d =\t%d\n",num1,num2,num1*num2);

break;

case '/':

printf("%d / %d =\t%d\n",num1,num2,num1/num2);

break;

case '%':

printf("%d %% %d =\t%d\n",num1,num2,num1%num2);

break;

default:

printf("Error! Invalid Operator.");

}

return 0;

}

Similar questions