第1个回答 2013-03-21
#include "stdio.h"
int main() {
int a, b, result;
char c;
while(1) {
scanf("%d%c%d", &a, &c, &b);
switch(c) {
case '+':
result = a+b;
break;
case '-':
result = a-b;
break;
case '*':
result = a*b;
break;
case '/':
result = a/b;
break;
default:
break;
}
printf("%d%c%d=%d\n", a, c, b, result);
}
}
这个行不本回答被网友采纳
第2个回答 2013-03-21
#include <stdio.h>
main()
{
float data1,data2,m;
char op;
printf("Please input data1 and data2\n");
scanf("%f%c%f",&data1,&op,&data2);
switch(op)
{
case'+':m=data1+data2;printf("%f\n",m);break;
case'-':m=data1-data2;printf("%f\n",m);break;
case'*':m=data1*data2;printf("%f\n",m);break;
case'/':m=data1/data2;
{
if(data2==0)printf("error!\n");
else printf("%f\n",m);break;
}
default:printf("error!\n");
}
}
第3个回答 2013-03-21
double a,b;
char c;
scanf("%lf%c%lf",&a,&c,&b);
switch(c)
{case '+':printf("%g%c%g=%g",a,c,b,a+b);break;
case '-':printf("%g%c%g=%g",a,c,b,a-b);break;
case '*':printf("%g%c%g=%g",a,c,b,a*b);break;
case '/':b?printf("%g%c%g=%g",a,c,b,a/b):puts("error");break;
default:printf("error");break;
}