The following program asks user an arithmetic
operator (+,-,*,/) and two operands and perform the corresponding
calculation on the operands.
# include <stdio.h>
int main() {
char o;
float num1,num2;
printf("Enter an operator: either + or - or *
or /\n\n=> ");
scanf("%c",&o);
printf("\nEnter two numbers:\n");
switch(o) {
case '+':
printf("\n%.1f + %.1f = %.1f\n",num1,
num2, num1+num2);
break;
case '-':
printf("\n%.1f - %.1f = %.1f\n",num1,
num2, num1-num2);
break;
case '*':
printf("\n%.1f * %.1f = %.1f\n",num1,
num2, num1*num2);
break;
case '/':
printf("\n%.1f / %.1f = %.1f\n",num1,
num2, num1/num2);
break;
default:
printf("\nError! operator is not
correct.\n");
break;
}
return 0;
}