雅芳的走珠香水哪款好:这道C语言编程题怎么做?

来源:百度文库 编辑:高考问答 时间:2024/05/06 01:08:09
给一个不多于5位的正整数,要求:
1.求出它是几位数;
2.分别输出每一位数字;
3.按逆序给出各位数字,例如原数为321,应输入123。

int fun(long a)
{
int i,n;
char d[10];
i=0;
do
{
d[i++]=a%10+48;
a=a\10;
}while(a>0)
printf("%d\n",i);
for(n=i-1;n>=0;n--)
printf("%c\t",d[n]);
printf("\n");
for(n=0;n<i;n++)
printf("%c\t",d[n]);
return i;
}

#include<stdio.h>
main()
{
long i,a,b,c,d,e,m;
while(scanf("%d",&i)==1)
{
if((i<=0)||(i>99999))
printf("error\n");
else
{
a=i/10000; /*万位*/
b=(i%10000)/1000; /*千位*/
c=(i%1000)/100; /*百位*/
d=(i%100)/10; /*十位*/
e=i%10; /*个位*/
if(a)
m=5;
else if(b)
m=4;
else if(c)
m=3;
else if(d)
m=2;
else
m=1;
printf("%d wei shu\n",m);
printf("wan wei shi %ld\nqian wei shi %ld\nbai wei shi %ld\nshi wei shi %ld\nge wei shi %ld\n",a,b,c,d,e);
}
switch(m)
{
case 5: printf("%ld%ld%ld%ld%ld",e,d,c,b,a);break;
case 4: printf("%ld%ld%ld%ld",e,d,c,b);break;
case 3: printf("%ld%ld%ld",e,d,c);break;
case 2: printf("%ld%ld",e,d);break;
case 1: printf("%ld",e);

}
}
return 0;
}

#include<stdio.h>
void main()
{
int i,Number,a[5],j;
printf("Input A Number: ");
scanf("%d",&Number);
for(i=0;Number;i++)
{
a[i]=Number%10;
Number/=10;
}
printf("\n Result: ");
for(j=0;j<i;j++)
printf("%d",a[j]);
}