给一个不多于5位的正整数,要求:1,求出是几位数;2,分别打印出每一位数字;3,按拟序打印出各位数字。例如原数是321,应输出123
參考答案:我对你的问题进行了认真的分析和解答:并且完全按照你的要求进行输出,源程序如下:(以下源程序都是经过实际测试的):
#include<stdio.h>
void main( )
{
int n,one,two,three,four,five;
printf("please input a number no more than 5 bit:");
scanf("%d",&n);
five=n/10000;
four=n%10000/1000;
three=n%1000/100;
two=n%100/10;
one=n%10;
if(five!=0)
{
printf("this is an five bit number\n");
printf("everybit is:%ld %ld %ld %ld %ld\n",five,four,three,two,one);
printf("the adverse order of everybit is:%ld %ld %ld %ld %ld\n",one,two,three,four,five);
}
else{
if(four!=0)
{
printf("this is an four bit number\n");
printf("everybit is:%ld %ld %ld %ld\n",four,three,two,one);
printf("the adverse order of everybit is:%ld %ld %ld %ld\n",one,two,three,four);
}
else{
if(three!=0)
{
printf("this is an three bit number\n");
printf("everybit is:%ld %ld %ld\n",three,two,one);
printf("the adverse order of everybit is:%ld %ld %ld\n",one,two,three);
}
else{
if(two!=0)
{
printf("this is an two bit number\n");
printf("everybit is:%ld %ld\n",two,one);
printf("the adverse order of everybit is:%ld %ld\n",one,two);
}
else
{
if(one!=0)
{
printf("this is an one bit number\n");
printf("everybit is:%ld\n",one);
printf("the adverse order of everybit is:%ld\n",one);
}
}
}
}
}
}