题解 | #加减乘除#
加减乘除
https://www.nowcoder.com/practice/fdc56f9b00b34c70ad36c61ef89e3fc3
#include <stdio.h> int main(){ int x, y; char sign; while(scanf("%d %c",&x, &sign) != EOF){ int result = 1; //阶乘时使用 if(sign == '!'){ for (int i = 1; i <= x; ++i) { result *= i; } printf("%d\n", result); } else{ scanf("%d", &y); switch(sign){ case '+': printf("%d\n", x+y);break; case '-': printf("%d\n", x-y);break; case '*': printf("%d\n", x*y);break; case '/': if (y == 0){ printf("error\n");break; } else{ printf("%d", x/y);break; } case '%': if (y == 0){ printf("error\n");break; } else{ printf("%d", x%y);break; } } } } return 0; }