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

25 lines
480 B
C
Raw Normal View History

2024-10-18 08:13:01 +00:00
#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;
}