#include <stdio.h>
int main() {
int a, b, res;
char op;
printf("Input first number: ");
scanf("%d", &a); // read first number
while (getchar() != '\n'); // skip all unread characters
printf("Input second number: ");
scanf("%d", &b); // read second number
while (getchar() != '\n'); // skip all unread characters
printf("Input the operation(+,-,*,/): ");
op = getchar(); // read the character of operation
switch (op) {
case '+':
res = a + b;
break;
case '-':
res = a - b;
break;
case '*':
res = a * b;
break;
case '/':
res = (float) a / b;
break;
default:
printf("Invalid operator\n");
return;
}
printf("%d %c %d = %d\n", a, op, b, res);
}
Comments
Leave a comment