题目:Calculate a+b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).
以下是我的代码,但是只得了10分,我不太明白是哪里不符合要求,我看其他人都是用字符串输出,但是我觉得直接输出更简便。
#include<stdio.h>
#include<math.h>
int main()
{
int a;
int b;
int count;
int i=0;
int n=0;
int m,m1,re;
scanf("%d %d",&a, &b);
count=a+b;
if(count<0)
{
printf("-");
count=-count;
}
if(count==0)
printf("0");
while(1)
{ m=pow(10,i);
if(count/m==0)
{
break;
}
n++;
i++;
}
for(i=n;i>0;i--)
{
if(i%3==0&&i!=0)
printf(",");
m1=pow(10,i-1);
re=(count/(m1))%10;
printf("%d",re);
}
}
这是官方给出的结果:
这是官方给的编译器输出:(我没看出来有什么问题)
希望能够得到解答,十分感谢。