请写C语言学生信息管理系统成绩排序
时间: 2023-12-27 13:05:06 浏览: 81
好的,下面是一个简单的学生信息管理系统的成绩排序程序,使用C语言编写:
```c
#include <stdio.h>
#include <string.h>
#define MAX_STUDENTS 100
typedef struct {
char name[20];
int score;
} Student;
int main() {
Student students[MAX_STUDENTS];
int num_students = 0;
// 读入学生信息
printf("请输入学生信息,每行一个,按Ctrl + D结束输入:\n");
while (num_students < MAX_STUDENTS && scanf("%s%d", students[num_students].name, &students[num_students].score) == 2) {
num_students++;
}
// 按成绩从高到低排序
for (int i = 0; i < num_students - 1; i++) {
for (int j = i + 1; j < num_students; j++) {
if (students[j].score > students[i].score) {
Student temp = students[i];
students[i] = students[j];
students[j] = temp;
}
}
}
// 输出排序结果
printf("按成绩从高到低排序后的学生信息如下:\n");
for (int i = 0; i < num_students; i++) {
printf("%s\t%d\n", students[i].name, students[i].score);
}
return 0;
}
```
这个程序定义了一个 `Student` 结构体,包含学生的姓名和成绩。首先,程序读入学生信息,然后按成绩从高到低排序,最后输出排序结果。
阅读全文
相关推荐














