2.分别打印出每以为数字
3. 按逆序打印出各位数字,例如原数321.输出123
#include <stdio.h>
main()
{
int k=0;
int a,t,n,i;
printf("请输入一个数:\n");
scanf("%ld",&a);
t=a;
n=a;
while(t>0)
{ t=t/10;
k++;
}
printf("这个数是一个%d位数\n",k);
switch(k)
{case 5: printf("这个数的万位数是:%d\n",a/10000);a=a%10000;
case 4: printf("这个数的千位数是:%d\n",a/1000);a=a%1000;
case 3: printf("这个数的百位数是:%d\n",a/100);a=a%100;
case 2: printf("这个数的十位数是:%d\n",a/10);a=a%10;
case 1: printf("这个数的个位数是:%d\n",a);
}
while(n>0)
{
i=n%10;
printf("%d",i);
n=n/10;
}
}
不用字符串的``不过好象很麻烦
#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);
}