| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1071 人关注过本帖
标题:【求助】int
取消只看楼主 加入收藏
写在人生边上
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2007-11-8
收藏
 问题点数:0 回复次数:1 
【求助】int
# include <stdio.h>
void main()
{
    int num;
    /* 下面定义的各变量,分别代表个位,十位,百位,千位,万位,十万位以及位数 */
    int indiv, ten, hundred, thousand;
    int ten_thousand, hundred_thousand, place;

    printf("请输入一个整数(0~999999):");
    scanf("%d", &num);

    /* 判断变量num的位数 */
    if(num > 99999)
        place = 6;
    else 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("每位数字为:");

    /* 求出num在各位上的值 */
    hundred_thousand = num/100000;
    ten_thousand = (num - hundred_thousand*100000)/10000;
    thousand = (num - hundred_thousand*100000 - ten_thousand*10000)/1000;
    hundred = (num - hundred_thousand*100000 - ten_thousand*10000
              - thousand*1000)/100;
    ten = (num - hundred_thousand*100000 - ten_thousand*10000
          - thousand*1000 - hundred*100)/10;
    indiv = num - hundred_thousand*100000 - ten_thousand*10000
            - thousand*1000 - hundred*100 - ten*10;

    /* 判断变量num的位数,并根据位数做出相应的输出 */
    switch(place)
    {
    case 1: printf("%d", indiv);
            printf("\n反序数字为:");
            printf("%d\n", indiv);
            break;
    case 2: printf("%d, %d", ten, indiv);
            printf("\n反序数字为:");
            printf("%d%d\n", indiv, ten);
            break;
    case 3: printf("%d, %d, %d", hundred, ten, indiv);
            printf("\n反序数字为:");
            printf("%d%d%d\n", indiv, ten, hundred);
            break;
    case 4: printf("%d, %d, %d, %d", thousand, hundred, ten, indiv);
            printf("\n反序数字为:");
            printf("%d%d%d%d\n", indiv, ten, hundred, thousand);
            break;
    case 5: printf("%d, %d, %d, %d, %d", ten_thousand, thousand,
                   hundred, ten, indiv);
            printf("\n反序数字为:");
            printf("%d%d%d%d%d\n", indiv, ten, hundred,
                    thousand, ten_thousand);
            break;
    case 6: printf("%d, %d, %d, %d, %d, %d", hundred_thousand,
                   ten_thousand, thousand, hundred, ten, indiv);
            printf("\n反序数字为:");
            printf("%d%d%d%d%d%d\n", indiv, ten, hundred, thousand,
                    ten_thousand, hundred_thousand);
            break;
    default: printf("Not find.\n");
             break;
    }
}
搜索更多相关主题的帖子: int 
2008-05-04 22:18
写在人生边上
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2007-11-8
收藏
得分:0 
我们都知道 ,int 型变量的范围是 -32767 - 32767 , 在TC 2.0 下 ,当输入    45678 ,TC下运行有误。

        但是在VC++ 6.0  下, 可以输出   45678     87654  ,这是为什么?

       难道  int 在 VC++ 6.0 下的范围不是  -32767 - 32767  
2008-05-04 22:22
快速回复:【求助】int
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016781 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved