这道题是非常基础的题,主要考察小数点精度的问题(小数点后两位)。用printf的话使用 printf ("%.2f\n", a)
即可,使用cout的话使用cout<<fixed<<setprecision(2)<<a;
头文件要包含include<iomanip>
Sample Input
4
+ 1 2
- 1 2
* 1 2
/ 1 2
Sample Output
3
-1
2
0.50
#include<stdio.h>
int main()
{
int n, a, b;
char c;
scanf("%d", &n);
while (n--)
{
getchar();
scanf("%c%d%d", &c, &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
a%b ? printf("%.2f\n", a*1.0 / b) : printf("%d\n", a / b);
}
return 0;
}