简易计算器,加减乘除优先级相同,从左往右依次计算
#include<stdio.h>int main(void)
{
int a,b,i=1;
char ch='a';
printf("Enter your inpression:");
while(ch!='='){
if(i%2==0) ch=getchar();
else {
scanf("%d",&a);
if(i==1) b=a;
else {
switch(ch){
case '+': b=b+a; break;
case '-': b=b-a; break;
case '*': b=b*a; break;
case '/': b=b/a; break;
}
}
}
i++;
}
printf("%d",b);
printf("\n");
return 0;
}