汉中施工人员招聘信息:C语言编程问题

来源:百度文库 编辑:高考问答 时间:2024/04/28 14:27:14
给一个不多于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);
}
}
}
}
}

}

#include <stdio.h>

int main()
{
long Num;
int a=0;
scanf("%ld",&Num);
printf("\n");
do
{
a++;/*得到位数*/
printf("%d",Num%10);/*作为字符串输出逆序*/
Num = Num / 10;

}while(Num);
printf("\n%d ",a);/*输出位数*/

return 0;

}

main( )
{
long a,b,c,d,e,x;
scanf("%ld",&x);
a=x/10000;/*分解出万位*/
b=x%10000/1000;/*分解出千位*/
c=x%1000/100;/*分解出百位*/
d=x%100/10;/*分解出十位*/
e=x%10;/*分解出个位*/
if (a!=0) printf("there are 5, %ld %ld %ld %ld %ld\n",e,d,c,b,a);
else if (b!=0) printf("there are 4, %ld %ld %ld %ld\n",e,d,c,b);
else if (c!=0) printf(" there are 3,%ld %ld %ld\n",e,d,c);
else if (d!=0) printf("there are 2, %ld %ld\n",e,d);
else if (e!=0) printf(" there are 1,%ld\n",e);
}