给出一个不多于5位的正整数,要求:
① 求出它是几位数;
② 分别打印出每一位数字;
③ 按逆序打印出各位数字,例如原数为321,应输出123。
#include <stdio.h>
void main()
{
int num, num1;
int count=0;
printf("please input the number:");
scanf("%d",&num1);
num=num1;
while(num!=0)
{
count++;
num=num/10;
}
printf("the number is one %d-bit number.\n", count);
num=num1;
while(count!=0)
{
int temp=1;
for(int i=1;i<count;i++)
temp=temp*10;
printf("%d ",num/temp);
count--;
num=num-(num/temp)*temp;
}
printf("\n==================\n");
num=num1;
while(num!=0)
{
printf("%d ", num%10);
num=(num-num%10)/10;
}
printf("\n==================\n");
}