1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-11-23 21:58:41 +00:00
202401-programming-assignments/【实践课内】2.选择结构1/7-4 选择-计算器2.c

25 lines
480 B
C

#include <stdio.h>
int main() {
int a, b;
char op;
scanf("%d %c %d", &a, &op, &b);
if (op == '+') {
printf("%d\n", a + b);
} else if (op == '-') {
printf("%d\n", a - b);
} else if (op == '*') {
printf("%d\n", a * b);
} else if (op == '/' && b != 0) {
printf("%.2lf\n", (double)a / b);
} else if (op == '%' && b != 0) {
printf("%d\n", a % b);
} else {
printf("Error\n");
}
return 0;
}