代码如下:
#include <stdio.h>
#include <string.h>
double add(double a,double b)
{
return (a+b);
}
double sub(double a,double b)
{
return (a-b);
}
double mul(double a,double b)
{
return a*b;
}
double div(double a,double b)
{
return a/b;
};
int main()
{
int i,n;
char c1,c2;
double a,b,t;
scanf("%d",&n);
getchar();
for (i=0;i<n;i++)
{
scanf("%c%c%c%c%lf,%lf%c",&c1,&c2,&c2,&c2,&a,&b,&c2);
getchar();
if(c1 == 'a')
{
t = add(a,b);
if(t == (int)t)
printf("%d\n",(int)t);
else
printf("%.2lf\n",t);
}
else if(c1 == 'm')
{
t = mul(a,b);
if(t == (int)t)
printf("%d\n",(int)t);
else
printf("%.2lf\n",t);
}
else if(c1 == 's')
{
t=sub(a,b);
if(t == (int)t)
printf("%d\n",(int)t);
else
printf("%.2lf\n",t);
}
else if (c1 == 'd')
{
if(b==0)
printf("error\n");
else
{
t = div(a,b);
if(t == (int)t)
printf("%d\n",(int)t);
else
printf("%.2lf\n",t);
}
}
}
return 0;
}