- 将整型数采用取余方式得到每一位数值,而后逆序输出。
- 注意每三位输出一个',',且注意和为'0'的情况。
/*
Created by HarvestWu on 2018/4/9.
*/
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
int a, b, sum, count = 0, c[10];
cin >> a >> b;
sum = a + b;
if (sum < 0)
{
printf("-");
sum = -sum;
}
else if (sum == 0)
{
printf("0");
}
while (sum)
{
c[count++] = sum % 10;
sum /= 10;
}
for (int i = count-1; i >= 0; i--)
{
printf("%d", c[i]);
if (i% 3 == 0&&i!=0)
printf(",");
}
return 0;
}