给一个不多于5位的正整数,要求:1)求出它是几位数 2)分别输出每一位 3)按逆序输出各位
#include<stdio.h>
main()
{
long int number;
int indiv,ten,hunderd,thousand,tenthousand,place;
printf("Please enter a number:\n");
printf("Please enter a number(0~99999):");
scanf("%ld",&number);
if(number>9999)
place=5;
else
if(number>999)
place=4;
else
if(number>99)
place=3;
else
if(number>9)
place=2;
else
if(number>=0)
place=1;
tenthousand=number/10000;
thousand=(int)(number-tenthousand*10000)/1000;
hunderd=(int)(number-tenthousand*10000-thousand*1000)/100;
ten=(int)(number-tenthousand*10000-thousand*1000-hunderd*100)/10;
indiv=number-tenthousand*10000-thousand*1000-hunderd*100-ten*10;
printf("Every palce is\n:");
switch(place)
{
case 5 : printf("%d %d %d %d %d\n",tenthousand,thousand,hunderd,ten,indiv);
printf("The opposite palce is\n:%d %d %d %d %d\n",indiv,ten,hunderd,thousand,tenthousand);
break;
case 4 : printf("%d %d %d %d\n",thousand,hunderd,ten,indiv);
printf("The opposite palce is\n:%d %d %d %d\n",indiv,ten,hunderd,thousand);
break;
case 3 : printf("%d %d %d\n",hunderd,ten,indiv);
printf("The opposite palce is\n:%d %d %d\n",indiv,ten,hunderd);
break;
case 2 : printf("%d %d\n",ten,indiv);
printf("The opposite palce is\n:%d %d\n",indiv,ten);
break;
case 1 : printf("%d",indiv);
printf("The opposite palce is\n:%d\n",indiv);
break;
default : printf("error");
}
getch();
}
输入数字:98765 是正确的,输出:
9 8 7 6 5
5 6 7 8 9
如果把红字的(int)强制转换符去掉结果就出现:
9 74 658 6557 3
3 6557 658 74 9
我要说的是"/"是取整数部分怎么会出现这样的情况,请大家帮帮忙~谢谢~