C语言编程实现从键盘输入四则运算计算结果

#include
#include
int main() {
int a,b;
char op;
printf("请输入四则运算的式子\n");
scanf("%d%c%d",&a,&op,&b);
switch(op){
case '+':printf("%d+%d=%d",a,b,a+b);
break;
case'-':printf("%d-%d=%d",a,b,a-b);
break;
case'*':printf("%d*%d=%d",a,b,a*b);
break;
case'/':if(b==0){
printf("错误,除数不能为0\n");
}else{
printf("%d/%d=%d",a,b,a/b);
break;}

}
return 0;
}

你可能感兴趣的:(c语言,开发语言)