求简单方法
给一个不多于5位的正整数,要求:1、求出它是几位数;2、按逆序打印出各位数字如:12345 实现54321 虽然我达到了要求,但是感觉这台傻瓜了还繁琐,请哪位能给帮忙给个简单的,谢谢了
#include <stdio.h>
main()
{
long int m;
int x1,x2,x3,x4,x5;
printf("please input the integer:\n");
scanf("%ld",&m);
if(m/10000==0)
if(m/1000==0)
if(m/100==0)
if(m/10==0)
{
printf("this integer has one number!\n");
printf("%d",m);
}
else
{
printf("this integer has two number!\n");
printf("%d",m%10);
printf("%d",m%100/10);
}
else
{
printf("this integer has three number!\n");
printf("%d",m%10);
printf("%d",m%100/10);
printf("%d",m%1000/100);
}
else
{
printf("this integer has four number!\n");
printf("%d",m%10);
printf("%d",m%100/10);
printf("%d",m%1000/100);
printf("%d",m%10000/1000);
}
else
{
printf("this integer has five number!\n");
printf("%d",m%10);
printf("%d",m%100/10);
printf("%d",m%1000/100);
printf("%d",m%10000/1000);
printf("%d",m/10000);
}
}