給一個不多於5位的正整數,要求:
(1)求出它是幾位數;
(2)分別輸出每一位數字;
(3)按逆序輸出各位數字,例如原數爲321,應輸出123。
#include<stdio.h>
int main()
{
int long x;
scanf("%d",&x);
if(x<=9)
{
printf("%d\n",1);
printf("%d",x);
}
if(x<99&&x>9)
{
printf("%d\n",2);
printf("%d%d",x/10,x%10);
}
if(x<999&&x>99)
{
printf("%d\n",3);
printf("%d%d%d",x/100,(x%100)/10,x%10);
if(x<9999&&x>999)
{
printf("%d\n",4);
printf("%d%d%d%d",x/1000,(x%1000)/100,(x%100)/10,x%10);
}
if(x<99999&&x>9999)
{
printf("%d\n",5);
printf("%d%d%d%d%d",x/10000,(x%10000)/1000,(x%1000)/100,(x%100)/10,x%10);
}
return 0;
}
}