题目:
代码:
#include<stdio.h>
int main()
{
int n,a,b;
char c;
float sum;
scanf("%d",&n);
getchar();
while(n>0)
{
c=getchar();
scanf("%d%d",&a,&b);
if(c=='+')
{
printf("%d\n",a+b);
}
else if(c=='-')
{
printf("%d\n",a-b);
}
else if(c=='*')
{
printf("%d\n",a*b);
}
else if(c=='/')
{
sum=(float)a/b;
if(a%b!=0)
printf("%.2f\n",sum);
else
printf("%d\n",a/b);
}
getchar();
n--;
}
return 0;
}
注意:这题本来很简单,但是!!!一直wrong!!!
为什么呢???结果就是没仔细读题!!!
The result should be rounded to 2 decimal places If and only if it is not an integer.
!!!only if it is not an integer.!!!
所以在输出除法的时候要加入判断!!!