#include
int main() {
int first;
int second;
char operator;
scanf("%d%c%d", &first,&operator, &second);
if (operator=='+') {
printf("=%d",first+second);
}else if (operator=='-'){
printf("=%d",first-second);
}else if (operator=='//'){
printf("=%d",first/second);
}else if (operator=='*'){
printf("=%d",first*second);
}else {
printf("=%d",first%second);
}
return 0;
}
除法运行结果不正确。其他4种运行结果对。
#include
int main() {
int first;
int second;
char operator;
scanf("%d%c%d", &first,&operator, &second);
if (operator=='+') {
printf("=%d",first+second);
}else if (operator=='-'){
printf("=%d",first-second);
}else if (operator=='/'){
printf("=%d",first/second);
}else if (operator=='*'){
printf("=%d",first*second);
}else {
printf("=%d",first%second);
}
return 0;
}
运行5种运算结果都正常,但是说我除号那里有错,加了转义符的运行结果就不正确,编译都不报错。