//也不是简易计算器,输入很少,整体还是很简单的。 #include "stdio.h" int recursion(int num){//求阶乘的递归 if(num == 1) return 1; else return recursion(num-1)*num; } int main(){ int num1,num2; char op; while (scanf("%d ",&num1)!=EOF){ scanf("%c",&op); switch (op) { case '+': scanf("%d",&num2); printf("%d\n",num1+num2); break; case '-': scanf("%d",&num2); printf("%d\n",num1-num2); break; case '*': scanf("%d",&num2); printf("%d\n",num1*num2); break; case '/': scanf("%d",&num2); if(num2 == 0){ printf("error\n"); break; } printf("%d\n",num1/num2); break; case '%': scanf("%d",&num2); if(num2 == 0){ printf("error\n"); break; } printf("%d\n",num1%num2); break; case '!': printf("%d\n", recursion(num1)); } } }