第5章后面有几个小问题,想了半天没有思路,希望高人指点,
1.给一个不多于5位的正整数,分别打印出每一位的数位,
2.按逆序打印出各位数学,如原数为123.输出是321.
我不知道这要怎么样去思索,指点一下就行,不劳您把代码写出来!
#include<stdio.h>
int main()
{
long num,t;
int count=0;
printf("输入一个不多于5位数的正整数:");
scanf("%ld",&num);
t=num;
while(t)
{
count++;
t=t/10;
}
printf("该数是个%d位数\n",count);
t=num;
while(t)
{
switch(count)
{
case 5:printf("该数的万位是%d\n",t/10000);t=t%10000;break;
case 4:printf("该数的千位是%d\n",t/1000);t=t%1000;break;
case 3:printf("该数的百位是%d\n",t/100);t=t%100;break;
case 2:printf("该数的十位是%d\n",t/10);t=t%10;break;
case 1:printf("该数的个位是%d\n",t);t=0;break;
}
count--;
}
printf("该数的回文数为:");
t=num;
while(t)
{
printf("%d",t%10);
t=t/10;
}
printf("\n");
return(0);
}