| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛

int a=0,b=0;cin>>a;while(a)cout<<(a-a/10*10)<<ends,++b,a/=10;cout<<endl<<b<<"位数";

```#include <stdio.h>
#include <stdlib.h>
int main()
{
int x, a, b, c, d, e;
//输入一个整数
scanf("%d", &x);
//以下是判断整数是否多于5位，多于判断出错，重新输入
while (x < 0 || x > 99999){
scanf("%d", &x);
}
//以下判断出该数是几位数
a = x / 10000;
b = x / 1000;
c = x / 100;
d = x / 10;
e = x - d * 10;
if (a >= 1 && a <= 9){
printf("%d is 5 bits!\n", x);
printf("%d %d %d %d %d\n", a, b-a*10, c-b*10, d-c*10, e);
printf("%d %d %d %d %d\n", e, d-c*10, c-b*10, b-a*10, a);
}
else if (b >= 1 && b <= 9){
printf("%d is 4 bits!\n", x);
printf("%d %d %d %d\n", b, c-b*10, d-c*10, e);
printf("%d %d %d %d\n", e, d-c*10, c-b*10, b);
}
else if (c >= 1 && c <= 9){
printf("%d is 3 bits!\n", x);
printf("%d %d %d\n", c, d-c*10, e);
printf("%d %d %d\n", e, d-c*10, c);
}
else if (d >= 1 && d <= 9){
printf("%d is 2 bits!\n", x);
printf("%d %d\n", d, e);
printf("%d %d\n", e, d);
}
else{
printf("%d is 1 bits!\n", x);
printf("%d\n", x);
}
system("pause");
return 0;
}```

1、求出它是几位数
0 算是 0位数，还是 1位数？

```#include <stdio.h>

int main( void )
{
int n;
scanf( "%d", &n );

unsigned count = 0;
char s[40] = { '-', '0', 0 };
char* p = s;
for( unsigned m=n<0?-n:+n; m; m/=10 )
{
++count;
if( p!=s || m%10!=0 )
*++p = m%10+'0';
}

printf( "%u, %s\n", count==0?1:count, s+(n>=0) );
}```

• 纯蓝之刃2020-10-21 17:54 送鲜花  3朵   附言：极简主义

a = x / 10000;
b = x / 1000;
c = x / 100;
d = x / 10;
e = x - d * 10;   // 这个是个位吗？

或 e = x - 10000 * a - 1000 * b - 100 * c - 10 * d

PS: 不好意思，我放肆了
• 6
• 1/1页
• 1