标题:求助:逆排序错误问题
只看楼主
心若止水
Rank: 1
等 级:新手上路
帖 子:89
专家分:0
注 册:2008-4-9
得分:0 
你定义的number为浮点型,而scanf函数中用的是%d,所以输出肯定错的。我改了一下:
#include "stdio.h"
int main (void)
{
    long number;
    unsigned int a,b,c,d,e,leap=0;
    clrscr();
    printf("qing shu ru yi ge bu duo yu 5 wei de zheng shu:\n");
    scanf("%ld",&number);
    if(number>99999)
    leap=1;
    a=number/10000;
    b=(number-10000*a)/1000;
    c=(number-10000*a-1000*b)/100;
    d=(number-10000*a-1000*b-100*c)/10;
    e= number-10000*a-1000*b-100*c-10*d;
    if(leap==0)
    {
        if(a!=0)
          {
               printf("zhe shi yi ge wu wei shu:\n");
            printf("ni xu shu chu shi:%u%u%u%u%u",e,d,c,b,a);
          }
        else if(b!=0)
        {
            printf("zhe shi si wei shu:\n");
            printf("ni xu shu chu shi:%u%u%u%u",e,d,c,b);
        }
        else if(c!=0)
        {
            printf("zhe shi yi ge san wei shu:\n");
            printf("ni xu shu chu shi:%u%u%u",e,d,c);
        }
        else if(d!=0)
        {
            printf("zhe shi yi ge liang wei shu:\n");
            printf("ni xu shu chu shi:%u%u",e,d);
        }
        else
        {
            printf("zhe shi yi ge yi wei shu:\n");
            printf("ni xu shu chu shi:%u",e);
        }
    }
        else
        printf("shu ru cuo wu!");
        getch();
}
运行结果是对的。
2008-04-28 16:11
yjcf
Rank: 1
来 自:西安工业大学
等 级:新手上路
帖 子:145
专家分:0
注 册:2008-3-29
得分:0 
你定义的number为浮点型,而scanf函数中用的是%d,所以输出肯定错的。
哦 这样啊~~又粗心了!!谢谢ls

泾溪石险人竞慎,终岁不闻倾覆人。却是平流无石处,时时闻说有沉论。
2008-04-28 21:50



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-211186-1-1.html




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

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