简单计算器
#include <stdio.h>
#include <math.h>
int main(){
int x, y;
char ch;
scanf("%d%c", &x, &ch);
while(ch != '='){
scanf("%d", &y);
if(ch == '/' && y == 0){
printf("ERROR");
return 0;
}
switch(ch){
case '+': x = x + y;break;
case '-': x = x - y;break;
case '*': x = x * y;break;
case '/': x = x / y;break;
}
scanf("%c", &ch);
}
printf("%d", x);
return 0;
}
运行结果: