小程序_数字逆序

#include <stdio.h>

/****************************************************************
题目:给一个不多于5位的正整数,
要求:
一、求它是几位数,
二、逆序打印出各位数字。
1. 程序分析:学会分解出每一位数,如下解释:
*****************************************************************/

void main(void)
{
int temp[5] = {0};
int num = 0;
int digit = 1;
int count = 0;

while(1)
{
printf("Pls input the num ");
scanf("%d",&num);

digit = 1;
if(0>num||100000<num)
{
printf("Number is out of range! ");
fflush(stdin);
continue;
}

temp[4] = (num/10000)%10;
temp[3] = (num/1000)%10;
temp[2] = (num/100)%10;
temp[1] = (num/10)%10;
temp[0] = num%10;

for(count = 4; count >= 0; count--)
{
if(0 !=temp[count])
{
digit = count+1;
break;
}
}

printf("It is a [%d] digit ",digit);
for(count = 0 ; count< digit ; count++ )
{
printf("%d",temp[count]);
}

printf(" ");

fflush(stdin);

}

}

/***************** 今天为了更好的明天 ******************/
原文地址:https://www.cnblogs.com/cheng-amy/p/5805747.html