给一个不多于5位数的正整数按逆序打印出来,如输入123输出321
#include<stdio.h>
void main()
{
long n,a;
int n1,n2,n3,n4,n5,b,c,d;
scanf("%d",&n);
if(n >= 0 && n < 100000)
{
if ( n >= 10000 && n <100000 )
{
a = n % 10000 ;
b = a % 1000 ;
c = b % 100 ;
d = c % 10 ;
n1 = (n - a) / 10000;
n2 = (a - b) / 1000;
n3 = (b - c) / 100;
n4 = (c - d) / 10;
n5 = d ;
printf("\nThe number =%d%d%d%d%d\n",n5,n4,n3,n2,n1);
}
else if ( n >= 1000 && n < 10000 )
{ a = n % 1000;
b = n % 100;
c = n % 10;
n1 = (n - a) / 1000;
n2 = (a - b) / 100;
n3 = (b - c) / 10;
n4 = c;
printf("\nThe number =%d%d%d%d\n",n4,n3,n2,n1);
}
else if ( n>=100 && n < 1000)
{
a = n % 100;
b = a % 10;
n1 = (n - a) / 100;
n2 = (b - a) / 10;
n3 = b;
printf("\nThe number =%d%d%d\n",n3,n2,n1);
}
else if ( n >= 10 && n < 100)
{
a = n % 10;
n1 = (n - a) / 10;
n2 = a;
printf("\nThe number =%d%d\n",n2,n1);
}
else
{
a = n;
printf("\nThe number =%d%d\n", a);
}
}
else printf("\nThe number out control\n");
}
为什么运行结果不对,输入98765是结果不对,但输入较小的数字如12345是是正确的。
在单步调试是全部错误。