c语言正序输出每个数字

2024-12-03 22:41:54
推荐回答(2个)
回答1:

#include
#include
main()
{
printf("please input a number below 6 numbers:");
int n;
scanf("%d",&n);
int a=10,b=1;
while((n/a)>=1)
{
a=a*10;
b++;
}
if(b>5)printf("below 6 numbers!");
else printf("This is a %d numbers number\n",b);
// 加一个int m=n;
for(;n>0;)
{
printf("%d ",n%10);
n = n/ 10;
} // 这个for循环改成
for(;m>0;)
{
printf("%d ",m%10);
m = m/ 10;
}

printf("\n");
for(;n>0,b>0;)
{
printf("%d ",n/pow(10,b));
n=n-pow(10,b);
b--;
}
printf("\n");
}

先试试?

回答2:

这样试试

#include

int main()
{
int n;
int a = 0, b = 0;

printf("please input a number below 6 numbers:");
scanf("%d",&n);

a = n;
while(0 < a)
{
a /= 10;
b++;
}
if(b>6)
{
printf("below 6 numbers!");
}
else
{
printf("This is a %d numbers number\n", b);
}
a = n;
while(0 < a)
{
printf("%d ", a%10);
a /= 10;
}

printf("\n");

return 0;
}