題目:
代碼:
#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;
}
注意:這題本來很簡單魁衙,但是!F实怼!一直wrongO朔俊W莞簟!
為什么呢炮姨?捌刮??結果就是沒仔細讀題J姘丁I鹱鳌!
The result should be rounded to 2 decimal places If and only if it is not an integer.
6昱伞6砣稀!only if it is not an integer.:檎АC行印!
所以在輸出除法的時候要加入判斷?前摹F穹贰!