wenglujun
wenglujun
关注数: 0
粉丝数: 0
发帖数: 46
关注贴吧数: 1
[求助]很郁闷的问题,初学者,希望前辈指教。 问题:给个不多于5位的正整数,求它的位数和每一位的数字和倒过来每一位的数字。。。。当输入等于大于40000时结果不正常1到39999结果正常。。。。why?#include"stdio.h"void main(){ long int num; int gewei,ten,hundred,thousand,ten_thousand,place; /*表示个位到万位,及位数*/ printf("请输入一个数(1~99999):"); scanf("%ld",&num); if(num>9999) place=5; else if(num>999) place=4; else if(num>99) place=3; else if(num>9) place=2; else place=1; printf("place=%d\n",place); printf("每一位数字:"); ten_thousand=num/10000; thousand=(num-ten_thousand*10000)/1000; hundred=(num-ten_thousand*10000-thousand*1000)/100; ten=(num-ten_thousand*10000-thousand*1000-hundred*100)/10; gewei=(num-ten_thousand*10000-thousand*1000-hundred*100-ten*10); switch(place) { case 5:printf("%d,%d,%d,%d,%d\n",ten_thousand,thousand,hundred,ten,gewei); printf("反序的各个位数字:"); printf("%d,%d,%d,%d,%d\n",gewei,ten,hundred,thousand,ten_thousand); break; case 4:printf("%d,%d,%d,%d\n",thousand,hundred,ten,gewei); printf("反序的各个位数字:"); printf("%d,%d,%d,%d\n",gewei,ten,hundred,thousand); break; case 3:printf("%d,%d,%d\n",hundred,ten,gewei); printf("反序的各个位数字:"); printf("%d,%d,%d\n",gewei,ten,hundred); break; case 2:printf("%d,%d\n",ten,gewei); printf("反序的各个位数字:"); printf("%d,%d\n",gewei,ten); break; case 1:printf("%d\n",gewei); printf("反序的各个位数字:"); printf("%d\n",gewei); break;} getch(); }
1
下一页