day22

题目:给一个不多于5位的正整数,要求:一、求它是几位数,二、逆序打印出各位数字。

程序

#include

int main(void)

{

int a,b,c,d,e,i;

long s;

printf("Please enter a number:");

scanf("%d",&s);

a=s/10000;

b=s/1000%10;

c=s/100%10;

d=s/10%10;

e=s%10;

if(a!=0)

printf("They are 5\n%d %d %d %d %d\n",e,d,c,b,a);

else if(b!=0)

printf("They are 4\n%d %d %d %d\n",e,d,c,b);

else if(c!=0)

printf("They are 3\n%d %d %d\n",e,d,c);

else if(d!=0)

printf("They are 2\n%d %d\n",e,d);

else if(e!=0)

printf("They are 1\n%d\n",e);

return 0;

}

输出样例

图片发自App

你可能感兴趣的:(day22)