main( )
{
long a;
int digits ,a5,a4,a3,a2,a1;
printf("\nInput a number(<100000) ");
scanf("%ld",&a);
if(a/10000>0) digits=5;
else if(a/1000>0) digits=4;
else if(a/100>0) digits=3;
else if(a/10>0) digits=2;
else digits=1;
printf("The number %ld contains %d digits",a,digits);
printf("\n");
switch(digits)
{
case 5:printf("%d ",a5=a/10000);
case 4:printf("%d ",a4=a%10000/1000);
case 3:printf("%d ",a3=a%1000/100) ;
case 2:printf("%d ",a2=a%100/10);
case 1:printf("%d ",a1=a%10);
}
printf("\n");
switch(digits)
{
case 5:printf("%d %d %d %d %d",a1,a2,a3,a4,a5);break;
case 4:printf("%d %d %d %d ",a1,a2,a3,a4);break;
case 3:printf("%d %d %d ",a1,a2,a3);break;
case 2:printf("%d %d ",a1,a2);break;
case 1:printf("%d ",a1);
}
printf("\nEnd");
}
试一试这个嘛,我们刚刚也在做这个程序,我用了这个,感觉不错