c语言练习29——输入一个不超过5位的数字,判断共几位数字,并逆序输出
作者:互联网
#include<stdio.h> #include<stdlib.h> /*题目:给出一个不超过5位的正整数,要求:一、求它是几位数,二、逆序打印出各位数字。*/ int main(){ int a,a1,a2,a3,a4,a5; while(1){ printf("请输入一个5位以内的数字:"); scanf("%d",&a); if(a<=9) printf("共1位数,逆序:%d\n",a); else if(a<=99){ a1=a%10; a2=a/10; printf("共2位数,逆序:%d%d\n",a1,a2);} else if(a<=999){ a1=a%10; a2=a/10%10; a3=a/100; printf("共3位数,逆序:%d%d%d\n",a1,a2,a3);} else if(a<=9999){ a1=a%10; a2=a/10%10; a3=a/100%10; a4=a/1000; printf("共4位数,逆序:%d%d%d%d\n",a1,a2,a3,a4);} else if(a<=99999){ a1=a%10; a2=a/10%10; a3=a/100%10; a4=a/1000%10; a5=a/10000; printf("共5位数,逆序:%d%d%d%d%d\n",a1,a2,a3,a4,a5);} else printf("输入错误,请重新输入\n"); } return 0; }
标签:数字,int,29,几位数,include,输入,逆序 来源: https://www.cnblogs.com/gougouwang/p/11415600.html