1.定义一个结构体数组,存放10个学生的学号,姓名,三门课的成绩 2.从键盘输入10个学生的以上内容 3.输出单门课成绩最高的学生的学号、姓名、以及该门课程的成绩 4.输出三门课程的平均分数最高的学生的学号、姓名及其平均分 5.将10个学生按照平均分数从高到低进行排序,输出结果,格式如下所示: number name math Chinese English average 103 tom 90 90 100 95 101 alice 90 80 70 80
时间: 2024-02-10 10:06:18 浏览: 58
好的,以下是代码实现:
```c
#include <stdio.h>
#include <string.h>
// 定义学生结构体
struct Student {
int number;
char name[20];
int math;
int chinese;
int english;
float average;
};
int main() {
struct Student students[10]; // 定义学生结构体数组
int i, j;
// 输入学生信息
for (i = 0; i < 10; i++) {
printf("请输入第%d个学生的学号、姓名、数学成绩、语文成绩、英语成绩:", i+1);
scanf("%d %s %d %d %d", &students[i].number, students[i].name, &students[i].math, &students[i].chinese, &students[i].english);
students[i].average = (students[i].math + students[i].chinese + students[i].english) / 3.0;
}
// 输出单门课成绩最高的学生信息
int max_score = -1; // 初始化成绩最高分数
int max_score_index = -1; // 初始化成绩最高学生的下标
for (i = 0; i < 10; i++) {
if (students[i].math > max_score) {
max_score = students[i].math;
max_score_index = i;
}
}
printf("数学成绩最高的学生信息:\n");
printf("学号:%d,姓名:%s,数学成绩:%d\n", students[max_score_index].number, students[max_score_index].name, students[max_score_index].math);
max_score = -1;
max_score_index = -1;
for (i = 0; i < 10; i++) {
if (students[i].chinese > max_score) {
max_score = students[i].chinese;
max_score_index = i;
}
}
printf("语文成绩最高的学生信息:\n");
printf("学号:%d,姓名:%s,语文成绩:%d\n", students[max_score_index].number, students[max_score_index].name, students[max_score_index].chinese);
max_score = -1;
max_score_index = -1;
for (i = 0; i < 10; i++) {
if (students[i].english > max_score) {
max_score = students[i].english;
max_score_index = i;
}
}
printf("英语成绩最高的学生信息:\n");
printf("学号:%d,姓名:%s,英语成绩:%d\n", students[max_score_index].number, students[max_score_index].name, students[max_score_index].english);
// 输出三门课程的平均分数最高的学生信息
float max_average = -1; // 初始化平均分最高分数
int max_average_index = -1; // 初始化平均分最高学生的下标
for (i = 0; i < 10; i++) {
if (students[i].average > max_average) {
max_average = students[i].average;
max_average_index = i;
}
}
printf("三门课程平均分最高的学生信息:\n");
printf("学号:%d,姓名:%s,平均分数:%.2f\n", students[max_average_index].number, students[max_average_index].name, students[max_average_index].average);
// 按照平均分数从高到低进行排序并输出结果
struct Student temp;
for (i = 0; i < 9; i++) {
for (j = i+1; j < 10; j++) {
if (students[i].average < students[j].average) {
temp = students[i];
students[i] = students[j];
students[j] = temp;
}
}
}
printf("按照平均分数从高到低进行排序的结果:\n");
printf("number\tname\tmath\tChinese\tEnglish\taverage\n");
for (i = 0; i < 10; i++) {
printf("%d\t%s\t%d\t%d\t%d\t%.2f\n", students[i].number, students[i].name, students[i].math, students[i].chinese, students[i].english, students[i].average);
}
return 0;
}
```
希望能够帮到你!
阅读全文