谭浩强5-7
作者:互联网
给出一个不多于5位的整数,要求 1、求出它是几位数 2、分别输出每一位数字 3、按逆序输出各位数字,例如原数为321,应输出123
源代码:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b,c,d,e,f,g,h;
scanf("%d",&a);
if(0<=a&&a<10){printf("1\n");
printf("%d\n%d\n",a,a);}
if(10<=a&&a<100){printf("2\n");b=a/10;c=a%10;d=10*c+b;
printf("%d %d\n%d\n",b,c,d);}
if(100<=a&&a<1000){printf("3\n");e=a/100;f=(a%100)/10;g=a%10;h=100*g+10*f+e;printf("%d %d %d\n%d",e,f,g,h);}
if(1000<=a&&a<10000){printf("4\n");b=a/1000;c=(a%1000)/100;d=(a%100)/10;e=a%10;f=1000*e+100*d+10*c+b;
printf("%d %d %d %d\n%d",b,c,d,e,f);}
if(10000<=a&&a<100000){printf("5\n");b=a/10000;c=(a%10000)/1000;d=(a%1000)/100;e=(a%100)/10;f=a%10;g=10000*f+1000*e+100*d+10*c+b;printf("%d %d %d %d %d\n%d",b,c,d,e,f,g);}
return 0;
}
标签:输出,源代码,数字,int,谭浩强,几位数,include 来源: https://blog.csdn.net/cxx11111/article/details/118912923