/*P112的5.7题目*/
#include <stdio.h>
main()
{
int A, B=0, a0, a1, a2, a3, a4;
printf("请输入一个不多于5位的正整数:");
scanf("%d", &A);
if(a0 = A/10000)
{ A %= 10000;
B = 5;
}
if(a1 = A/1000)
{ A %= 1000;
B = B == 0 ? 4 : B;
}
if(a2 = A/100)
{ A %= 100;
B = B == 0 ? 3 : B;
}
if(a3 = A/10)
{ A %= 10;
B = B == 0 ? 2 : B;
}
if(a4 = A/1)
B = B == 0 ? 1 : B;
printf("你输入的是%d位数\n", B);
if(B>=1)
printf("个位数是%d", a4);
if(B>=2)
printf(", 十位数是%d", a3);
if(B>=3)
printf(", 百位数是%d", a2);
if(B>=4)
printf(", 千位数是%d", a1);
if(B==5)
printf(", 万位数是%d", a0);
printf("\n原数的逆序输出为:");
if(B>=1)
printf("%d",a4);
if(B>=2)
printf("%d",a3);
if(B>=3)
printf("%d",a2);
if(B>=4)
printf("%d",a1);
if(B==5)
printf("%d",a0);
printf("\n");
}
|