下面的程序错那了?为何不是我要的结果

来源:百度知道 编辑:UC知道 时间:2024/09/24 22:47:39
main()
{
long int num;
int indiv,ten,hundred,thousand,ten_thousand,place;
char s[]={"\n the backformation is "};
printf("please put into anumber between 0 and 9999");
scanf("%d",&num);
ten_thousand=num/10000;
thousand=(int)(num-ten_thousand*10000)/1000;
hundred=(int)(ten_thousand*10000-thousand*1000)/100;
ten=(int)(ten_thousand*10000-thousand*1000-hundred*100)/10;
indiv=(int)(ten_thousand*10000-thousand*1000-hundred*100-ten*10);

if(num>=10000)
place=5;
else if(num>=1000)
place=4;
else if (num>=100)
place=3;
else if (num>=10)
place=2;
else place=1;
printf("place=%d\n",place);
printf("every place is:");
switch(place)
{case 5: printf("%d,%d,%d,%d,%d",ten_thousand,thousand,hundred,ten,indiv);
printf("%s",s)

main()
{
long int num;
int indiv,ten,hundred,thousand,ten_thousand,place;
char s[]={"\n the backformation is "};
printf("please put into anumber between 0 and 9999");
scanf("%ld",&num);
//IF 0<NUM<99999 ......
ten_thousand=num/10000;
thousand=(int)(num-ten_thousand*10000)/1000;
hundred=(int)(ten_thousand*10000-thousand*1000)/100;//hundred;我抗议,为什么thousand有num-,而我没有
ten=(int)(ten_thousand*10000-thousand*1000-hundred*100)/10;//ten;支持hundred
indiv=(int)(ten_thousand*10000-thousand*1000-hundred*100-ten*10);
//弱弱地问下,这样可以吗,indiv=num%10?
//我暂且相信你下面没有错误(心虚,Sorry),把这些改了先,
//但是我建议;重新设计,使用数组来存放分解的数字,用循环把重复的劳动交给计算机
//这样做的好处;容易扩展到更多的位,但是,你不需要更多的声明和更多的代码行
//你觉得怎么样
/*举个例子
long int TMP;
INT signum;//位数
INT numx[5];
......
for(TMP=num,signum=0;TMP;TMP/=10) numx[signum++]=TMP%10;
//记得,已经反过来了

*/