有个程序不知道为什么编译不到想要的结果,求指导
程序代码:此程序是求五位数的位数,相应位上的数和把该五位数逆序输出
但是我编完后发现我输入五位数的都可以,但小于五位数的就不可以了
若输入12,会有ten-thousand=1,正常应该是0才对,只有这里有问题,不过就是没法知道哪里错,求指导,谢谢
程序如下:
# include<stdio.h>
int main()
{
int one,ten,hundred,thousand,ten_thousand,x,place;
printf("enter a number(less 5 digit)\t");
scanf("%d",&x);
if(x>99999||x<=0) printf("enter a wrong number, enter again please\n");
else
{
if(x>9999) place=5;
else if(x>999) place=4;
else if(x>99) place=3;
else if(x>9) place=2;
else place=1;
printf("digit=%d\n",place);
printf("the number in the digit:");
one=x%10;
ten=(x-one)%100/10;
hundred=(x-ten*10-one)%1000/100;
thousand=(x-hundred*100-ten*10-one)%10000/1000;
ten_thousand=(x-thousand*1000-hundred*100-ten*10-one)/10000;
printf("one=%d,ten=%d,hundred=%d,thousand=%d,ten-tousand=%d\n",one,ten,hundred,thousand,ten-thousand);
switch(place)
{
case(1):printf("%d\n",one);break;
case(2):printf("%d%d\n",one,ten);break;
case(3):printf("%d%d%d\n",one,ten,hundred);break;
case(4):printf("%d%d%d%d\n",one,ten,hundred,thousand);break;
case(5):printf("%d%d%d%d%d\n",one,ten,hundred,thousand,ten-thousand);break;
}
}
return 0;
}
[ 本帖最后由 zhenaaaa 于 2013-5-2 22:49 编辑 ]







