题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1170
题目描述:
思路
接受n个测试案例,然后每个案例分别是(四则运算的符号 第一个数 第二个数)。然后进行对应的四则运算输出答案(**注意:**最后除法的时候,整除的就直接输出;如果是非整除的需要四舍五入保留两位小数输出)。
AC代码
#include<stdio.h>
int main(){
int n;
char ch;
int a,b;
int result;
float frs;//用来记录除法除出来的数
scanf("%d",&n);
while(n--){
a=0;
b=0;
getchar();//接受回车
scanf("%c%d%d",&ch,&a,&b);
// printf("你输入的:%c %d %d\n",ch,a,b);
result = 0;
if(ch=='+'){
result = a + b;
printf("%d\n",result);
}else if(ch=='-'){
result = a-b;
printf("%d\n",result);
}else if(ch == '*'){
result = a*b;
printf("%d\n",result);
}else if(ch == '/'){
if(a%b==0){
result = a/b;
printf("%d\n",result);
}else{
frs = a/(b*1.00);
printf("%.2f\n",frs);
}
}
}
return 0;
}