1001:将两数之和转换成3位一逗号
Sample Input
-1000000 9
Sample Output
-999,991
Sample Input
-1000000 9
Sample Output
-999,991
#include<iostream>
using namespace std;
#include<stdio.h>
void format(int num)
{
if(num>=1000)
{
format(num/1000);
printf(",%03d",num%1000);
}
else
{
cout<<num;
}
}
int main()
{
int a;
int b;
int sum;
cin>>a;
cin>>b;
sum=a+b;
if(sum<0)
{
cout<<"-";
sum = -sum;
}
format(sum);
}
本文介绍了如何将两数之和转换为3位一逗号的格式输出,并通过C++代码实现。主要内容包括输入两数、计算和输出结果,特别关注负数情况下的处理。
451

被折叠的 条评论
为什么被折叠?



