题解 | #加减乘除#
加减乘除
https://www.nowcoder.com/practice/fdc56f9b00b34c70ad36c61ef89e3fc3
#include<cstdio> int fun(int n){ if(n ==1){ return 1; }else{ return n*fun(n-1); } } int main(){ int a,b; char c; while(scanf("%d %c %d",&a,&c,&b) != EOF){ switch(c){ case '+' : printf("%d\n",a+b); break; case '-' : printf("%d\n",a-b); break; case '*' : printf("%d\n",a*b); break; case '/' : if(b == 0){ printf("error\n"); }else{ printf("%d\n",a/b); } break; case '%' : if(b == 0){ printf("error\n"); }else{ printf("%d\n",a%b); } break; case '!' : printf("%d\n",fun(a)); break; } } }