int main(int argc, char* argv[])
{
int a,b;
char mark ;
while(1)
{
printf("Please enter data:\n");
scanf("%d%c%d",&a,&mark,&b);
switch(mark)
{
case '+': printf("a+b = %d\n",a+b);
break;
case '-': printf("a-b = %d\n", a-b);
break;
case '*': printf("a*b = %d\n", a*b);
break;
case '/' : printf("a/b = %d\n", a/b);
break;
default: break ;
}
}
运行结果:
Please enter data:
1+1
a+b = 2
Please enter data:
2*3
a*b = 6
Please enter data:
2-3
a-b = -1
Please enter data:
2/3
a/b = 0