算术运算符计算机如何识别?
#include<stdio.h>int main()
{
int a,b,result;
char ope; //operator:运算符
printf("请输入数字和运算符:");
scanf("%d%c%d",&a,&ope,&b);
switch(ope)
{
case '+':result = a + b;break;
case '-':result = a - b;break;
case '*':result = a * b;break;
case '/':result = a / b;break;
case '%':result = a % b;break;
default :printf("illegal operator\n");
}
printf("%d",result);
return 0;
}
错误:比如输入3+2 结果是 illegal operator。如果输入 3 43 2 结果是5!关键是算术运算符如何被计算机识别!