| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1754 人关注过本帖
标题:排序算法没起作用就好像这个算法不存在一样
取消只看楼主 加入收藏
domore
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2019-7-25
结帖率:60%
收藏
已结贴  问题点数:5 回复次数:0 
排序算法没起作用就好像这个算法不存在一样
图片附件: 游客没有浏览图片的权限,请 登录注册


#include<stdio.h>
struct Student
    {
    int num;    //学号
    char name[20];    //名字
    float score;     //分数
    };


int main()
    {
    struct Student stu[5]=
            {
            {10010,"Li",80},
            {10015,"Po",90},
            {10020,"Wu",76},
            {10034,"Qi",79},
            {10056,"Zhang",89}
            };
    struct Student temp;    //交换用到的结构体变量temp
    const int n=5;
    int i,j;
    printf("the order is:\n");
    for(i=0;i<n-1;i++)      //按分数高低排序
        for(j=i+1;j<n;j++)
            if(stu[j].score>stu[i].score)
           //temp=stu[i];stu[i]=stu[j];stu[j]=temp;
           temp=stu[j];stu[j]=stu[i];stu[i]=temp;
    for(i=0;i<n;i++)
        printf("%6d %8s %6.2f\n",stu[i].num,stu[i].name,stu[i].score);
    return 0;
    }
搜索更多相关主题的帖子: 排序 算法 stu int temp 
2019-08-06 05:15
快速回复:排序算法没起作用就好像这个算法不存在一样
数据加载中...
 
   



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

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