函数原型:void fun(int n,char *res);
如输入:
123
则输出为:
123
又如输入:
57839780
则输出为:
57,839,780
第1个回答 2018-05-18
#include<>
void f1(char *s,char c) { char b;
while ( *s ) { b=*s; *s=c; c=b; s++; }
*s=c; s++; *s=0;
}
void fun(int n,char *res) { int i,m;
m=0; *res=0;
while ( n ) {
if ( m&&m%3==0 ) f1(res,',');
f1(res,n%10+'0');
n/=10;
m++;
}
}
void main() { int a; char s[40];
scanf("%d",&a); fun(a,s); printf("%s\n",s);
}本回答被提问者和网友采纳
void f1(char *s,char c) { char b;
while ( *s ) { b=*s; *s=c; c=b; s++; }
*s=c; s++; *s=0;
}
void fun(int n,char *res) { int i,m;
m=0; *res=0;
while ( n ) {
if ( m&&m%3==0 ) f1(res,',');
f1(res,n%10+'0');
n/=10;
m++;
}
}
void main() { int a; char s[40];
scanf("%d",&a); fun(a,s); printf("%s\n",s);
}本回答被提问者和网友采纳