给一个不多于5位的正整数,要求:一、求它是几位数,二、逆序打印出各位数字。
#include "stdafx.h"
int output(int);
int main(int argc, char* argv[])
{
int num;
printf("Please enter a integer:\n");
scanf("%d",&num);
output(num);
return 0;
}
int output(int x){
if (x<=9)
printf("你输入的是1位数\n");
else if(x<=99)
printf("你输入的是2位数\n");
else if(x<=999)
printf("你输入的是3位数\n");
else if(x<=9999)
printf("你输入的是4位数\n");
else if(x<=99999)
printf("你输入的是5位数\n");
while (x > 0) { //x大于0就不停循环
tprintf("%d",x%10); //输出个位
x /= 10; //除以10 循环
}
return 0;
} 2012年3月9日