1 #include<stdio.h> 2 3 int main(void) 4 { 5 char ch; 6 int number; 7 int flag = 0; 8 int ret; 9 10 scanf("%d", &number); //读入一个数字 11 ret = number; //如果只有一个操作数,那么结果就是这个操作数 12 ch = getchar(); //读下一个运算符 13 while (ch != '=') //如果运算符不是=,读入下一个操作数 14 { 15 scanf("%d", &number); 16 switch (ch) 17 { 18 case '+':ret = ret + number; break; 19 case '-':ret = ret - number; break; 20 case '*':ret = ret * number; break; 21 case '/':if (number == 0) {flag = 1;break;} else {ret = ret / number; break;} 22 default:flag = 1; break; 23 } 24 ch = getchar(); 25 } 26 27 if (flag) 28 { 29 printf("ERROR "); 30 } 31 else 32 { 33 printf("%d", ret); 34 } 35 36 return 0; 37 }