/*
案例2 整数的三位分节格式2
负数
*/
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int n,i=1;
char a[20],*ptr;
bool negative=false;
ptr = a;
cout << "Please input a integer:";
cin >> n;
if (n<0)
{
negative=true;
n=abs(n);
}
do{
if(i%4)
{
*ptr = n%10+'0';
n = n/10;
}
else *ptr = ',';
ptr++;
i++;
}while(n);
cout << "The standard output:";
if (negative==true)
{
cout<<"-";
}
do{
ptr--;
i--;
cout << *ptr;
}while(i>1);
cout << endl;
return 0;
}
整数的三位分节格式
最新推荐文章于 2023-12-26 09:43:14 发布