/* 编写一个简单的计算器程序,输入格式为:data1 op data2是参加运算的两个数, op为运算符,它的取值只能是+、-、*/ #include<stdio.h> main() { int data1,data2; char op; scanf("%d%c%d",【1】); switch(【2】) { case '+':printf("%d+%d=%d",data1,data2,data1+data2);break; case '-':printf("%d-%d=%d",data1,data2,data1-data2);break; case '*':printf("%d*%d=%d",data1,data2,data1*data2);break; case '/':if(【3】) {printf("分母不能为0!!");break;} else printf("%d/%d=%f",data1,data2,(【4】)data1/data2);break; default:break; } }
/* 编写一个简单的计算器程序,输入格式为:data1 op data2是参加运算的两个数, op为运算符,它的取值只能是+、-、*/ #include<stdio.h> main() { int data1,data2; char op; scanf("%d%c%d",&data1,&op,&data2); switch(op) { case '+':printf("%d+%d=%d",data1,data2,data1+data2);break; case '-':printf("%d-%d=%d",data1,data2,data1-data2);break; case '*':printf("%d*%d=%d",data1,data2,data1*data2);break; case '/':if(data2==0) {printf("分母不能为0!!");break;} else printf("%d/%d=%f",data1,data2,(float)data1/data2);break; default:break; } }
标签:case,printf,C语言,break,计算器,填空,op,data1,data2 From: https://www.cnblogs.com/xkdn/p/17100364.html