CNET中国旗舰网站

ZDNet China | CNET科技资讯网 | 政府采购 | 行业网站联盟




 
标题: [问答] 一到c程序问题(所有分数了)
CNET开发专家团
专家组
Rank: 10Rank: 10Rank: 10



UID 259939
精华 1
积分 53
帖子 4
威望 -2
ZD币 16 元
阅读权限 255
注册 2007-11-9
状态 离线
  楼主
发表于 2008-4-7 15:55  资料  个人空间  短消息  加为好友 
开发者在线

一到c程序问题(所有分数了)

题目是输入一个0到99999之间的数,1:求出它有几位;2:打印出每一位
<br>3:按逆序打印出各位数字,例如原数为321,应输出123.
<br>整个程序如下,出现了一个问题当输入的数大于40000时就会出现错误,在0到39999之间都正常,请高手指点下。
<br>main()
<br>{ long int num;
<br>  int place,ten_thousand,thousand,huandred,ten,indiv;
<br>  printf("please input the number(0~99999):n");
<br>
<br>  scanf("%ld",&num);
<br>  if(num&gt;9999)place=5;
<br>  else if(num&gt;999)place=4;
<br>  else if(num&gt;99)place=3;
<br>  else if(num&gt;9)place=2;
<br>  else place=1;
<br>  printf("place=%d  n",place);
<br>
<br>
<br>
<br>   ten_thousand=num/10000;
<br>  thousand=(num-ten_thousand*10000)/1000;
<br>  huandred=(num-ten_thousand*10000-thousand*1000)/100;
<br>  ten=(num-ten_thousand*10000-thousand*1000-huandred*100)/10;
<br>  indiv=num-ten_thousand*10000-thousand*1000-huandred*100-ten*10;
<br>
<br>  switch(place)
<br>  {
<br>   case 5:printf("%d,%d,%d,%d,%dn",ten_thousand,thousand,huandred,ten,indiv);
<br>   printf("%d%d%d%d%d",indiv,ten,huandred,thousand,ten_thousand);
<br>   break;
<br>
<br>   case 4:printf("%d,%d,%d,%dn",thousand,huandred,ten,indiv);
<br>   printf("%d%d%d%d",indiv,ten,huandred,thousand);
<br>   break;
<br>   case 3:printf("%d,%d,%dn",huandred,ten,indiv);
<br>   printf("%d%d%d",indiv,ten,huandred);
<br>   break;
<br>   case 2:printf("%d,%dn",ten,indiv);
<br>   printf("%d%d",indiv,ten);
<br>   break;
<br>   case 1:printf("%dn",indiv);
<br>   printf("%d",indiv);
<br>   break;
<br>  }
<br>  
<br>
<br>}



这是一篇来自百度知道的问题

顶部
CNET开发专家团
专家组
Rank: 10Rank: 10Rank: 10



UID 259939
精华 1
积分 53
帖子 4
威望 -2
ZD币 16 元
阅读权限 255
注册 2007-11-9
状态 离线
  沙发
发表于 2008-4-7 15:55  资料  个人空间  短消息  加为好友 
------------



这是一篇来自百度知道的问题

顶部
热点频道推荐: C/S开发| 数据库| WEB开发| 嵌入式| 项目管理|
 



当前时区 GMT+8, 现在时间是 2009-7-4 19:05

  Powered by Discuz! 5.5.0 © 2001-2007 Comsenz Inc.
Processed in 0.064862 second(s), 3/3 queries

清除 Cookies - 联系我们 - ZDNetChina中文社区 - 无图版