您的位置:首页 > 其它

有n个学生的信息(包括学号、姓名、成绩),要求按照成绩的高低顺序输出各学生的信息。

2013-03-20 10:07 981 查看
/*

============================================================================

Name : C12.c

Author :

Version :

Copyright : Your copyright notice

Description : Hello World in C, Ansi-style

============================================================================

*/

#include <stdio.h>

#include <stdlib.h>

struct Student {

int stuid;

char name[30];

float score;

};

int main(void) {

//初始化结构体

struct Student stu[5] =

{ { 10101, "aaa", 37 }, { 10101, "bb", 67 },

{ 10103, "liming", 34 }, { 10104, "lixiao", 78 }, { 10105,

"ccc", 45 } };

struct Student temp;

int i, j;

for (i = 0; i < 4; i++) {

for (j = 0; j < 4 - i; j++) {

if (stu[j].score > stu[j + 1].score) {

temp = stu[j];

stu[j] = stu[j + 1];

stu[j + 1] = temp;

}

}

}

//输出结构体的内容

for (i = 0; i < 5; i++) {

printf("第%d个学生信息:学号:%d,姓名:%s成绩:%.2f\n", i+1,stu[i].stuid, stu[i].name,

stu[i].score);

}

return EXIT_SUCCESS;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐