写一个按照学生成绩排名的程序c++
时间: 2023-05-23 11:00:56 浏览: 51
好的,以下是一个简单的按学生成绩排序的程序的代码:
```
#include <stdio.h>
struct Student {
char name[20];
int score;
};
int main() {
int n;
printf("请输入学生的数量:");
scanf("%d", &n);
struct Student students[n];
for (int i = 0; i < n; i++) {
printf("请输入第%d个学生的姓名和分数:", i + 1);
scanf("%s %d", students[i].name, &students[i].score);
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (students[i].score < students[j].score) {
struct Student temp = students[i];
students[i] = students[j];
students[j] = temp;
}
}
}
printf("按学生成绩降序排列的结果如下:\n");
for (int i = 0; i < n; i++) {
printf("姓名:%s 分数:%d\n", students[i].name, students[i].score);
}
return 0;
}
```
这个程序会先让用户输入学生数量,然后依次输入每个学生的姓名和分数,并根据分数降序排列最后输出。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)