C++编程,关于三位分节格式.希望大家帮帮忙

来源:百度知道 编辑:UC知道 时间:2024/06/04 04:29:17
编写程序,将某一个输入位数不确定的正整数按照标准的三位分节格式输出,例如,当用户输入82668634时,程序应该输出82,668,634。

#include<iostream.h>
#include<stdlib.h>

void main()
{
char temp[100];
int i,j,k;

i=0;
while(1)
{
temp[i]=cin.get();
if(temp[i++]==10)
break;
}
i--;
j=i%3;
for(k=0;k<j;k++)
{
cout<<temp[k];
}
if(j!=0)
cout<<',';
j=0;
for(;k<i;k++,j++)
{
if(j>2)
{
j=0;
cout<<',';
}
cout<<temp[k];
}
cout<<endl;
system("pause");
}