| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 403 人关注过本帖
标题:改错 查询时不对
只看楼主 加入收藏
zhb151017212
Rank: 1
等 级:新手上路
帖 子:41
专家分:6
注 册:2012-10-15
结帖率:73.33%
收藏
已结贴  问题点数:10 回复次数:4 
改错 查询时不对
#include<stdio.h>   
struct Staff{
        char  name[20];
        double num;
    };
int main()
{
    int i,j, p=0;
    double key;
    struct Staff temp;
struct Staff staff[10]={{"郑 兵",201003020076},
                        {"宋 琪",20100302001},
                        {"宋 健",201003020077},
                        {"丹 丹",201003020054},
                        {"马 文",201003020090},
                        {"孙 林",201003020017},
                        {"王 昆",201003020012},
                        {"段 鹏",201003020040},
                        {"小 六",201003020080},
                        {"李 勇",201003020069}};     
    for(i=0;i<10;i++)
        printf("%s %.0lf\n",staff[i].name,staff[i].num);
        for(j=0;j<10;j++)
            for(i=0;i<9-j;i++)
                if(staff[i].num>staff[i+1].num){
                    temp=staff[i];
                staff[i]=staff[i+1];
                staff[i+1]=temp;
                }
                for(i=0;i<10;i++)
                    printf("从小到大输出:%s %.0lf\n",staff[i].name,staff[i].num);

                while(p==0){
                    printf("input a staff's number:\n");//查询
                    scanf("%f",&key);
                    for(i=0;i<10;i++)
                    if(key==staff[i].num)
                    {
                        printf("%s %.0lf\n",staff[i].name,staff[i].num);
                        p=1;   
                    }
                    else{
                    
                        }
                    if(p==0)
                        printf("输入有误,重新出入!\n");
                }
                        return 0;      
}
搜索更多相关主题的帖子: double 查询 include 
2012-11-04 17:25
a635958000
Rank: 4
等 级:业余侠客
帖 子:55
专家分:253
注 册:2012-10-26
收藏
得分:10 
#include<stdio.h>   
struct Staff{
        char  name[20];
        double num;
    };
int main()
{
    int i,j, p=0;
    double key;
    struct Staff temp;
struct Staff staff[10]={{"郑 兵",201003020076},
                        {"宋 琪",20100302001},
                        {"宋 健",201003020077},
                        {"丹 丹",201003020054},
                        {"马 文",201003020090},
                        {"孙 林",201003020017},
                        {"王 昆",201003020012},
                        {"段 鹏",201003020040},
                        {"小 六",201003020080},
                        {"李 勇",201003020069}};     
    for(i=0;i<10;i++)
        printf("%s %.0lf\n",staff[i].name,staff[i].num);
        for(j=0;j<10;j++)
            for(i=0;i<9-j;i++)
                if(staff[i].num>staff[i+1].num)
                {
                    temp=staff[i];
                staff[i]=staff[i+1];
                staff[i+1]=temp;
                }
                for(i=0;i<10;i++)
                    printf("从小到大输出:%s %.0lf\n",staff[i].name,staff[i].num);

                while(p==0)
                {
                    printf("input a staff's number:\n");//查询
                    scanf("%lf",&key);
                    for(i=0;i<10;i++)
                    if(key==staff[i].num)
                    {
                        printf("%s %.0lf\n",staff[i].name,staff[i].num);//此处输出应是lf格式
                        p=1;   
                    }
                    else{
                    
                        }
                    if(p==0)
                        printf("输入有误,重新出入!\n");
                }
                        return 0;      
}
2012-11-05 17:03
小可不睬
Rank: 1
等 级:新手上路
帖 子:6
专家分:7
注 册:2012-11-5
收藏
得分:0 
这个我也不知道。。。。
2012-11-05 17:20
zhb151017212
Rank: 1
等 级:新手上路
帖 子:41
专家分:6
注 册:2012-10-15
收藏
得分:0 
回复 2楼 a635958000
为啥在scanf中输入f时,不能查询呀?float允许的最大值不也是15位嘛?
2012-11-05 20:12
a635958000
Rank: 4
等 级:业余侠客
帖 子:55
专家分:253
注 册:2012-10-26
收藏
得分:0 
回复 4楼 zhb151017212
因为你前面在定义key时定义的是double格式啊。
2012-11-06 10:10
快速回复:改错 查询时不对
数据加载中...
 
   



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

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