给一位不多余5位的正整数,要求:求出它是几位数,分别输出每一位数字,按逆序输出各位数字

#include
int Weishu(int number) //求出位数
{
 int p;
    if (number>9999)
         p = 5;
    else if(number>999)
         p = 4;
    else if(number>99)
         p = 3;
    else if(number>9)
         p = 2;
    else p = 1;
    return p;
}
int Shuzi(int number) //求每位数
{
 int a,b,c,d,e;
 a = number/10000;
    b = (number-a*10000)/1000;
    c = (number-a*10000-b*1000)/100;
    d = (number-a*10000-b*1000-c*100)/10;
    e = (number-a*10000-b*1000-c*100-d*10);
    printf("万位数:%d,千位数:%d,百位数:%d,十位数:%d,个位数:%d\n",a,b,c,d,e);
}
void Nixu(int number) //逆序
{
    int a,b,c,d,e;
 a = number/10000;
    b = (number-a*10000)/1000;
    c = (number-a*10000-b*1000)/100;
    d = (number-a*10000-b*1000-c*100)/10;
    e = (number-a*10000-b*1000-c*100-d*10);
    int z = Weishu(number);
    switch (z)
 {
   case 1:
        {
     printf("逆序为:%d\n",e);
     }break;
   case 2:
        {
   printf("逆序为:%d%d\n",e,d);
         }break;
   case 3:
        {
     printf("逆序为:%d%d%d\n",e,d,c);
         }break;
   case 4:
        {
          printf("逆序:%d%d%d%d\n",e,d,c,b);
         }break;
   case 5:
         {
    printf("逆序为:%d%d%d%d%d\n",e,d,c,b,a);
          }break;
 }
}   
int main()
{
 int number;
 scanf("%d",&number);
 printf("位数:%d\n",Weishu(number));
 Shuzi(number);
 Nixu(number);
 return 0;
}

你可能感兴趣的:(给一位不多余5位的正整数,要求:求出它是几位数,分别输出每一位数字,按逆序输出各位数字)