用C语言写
时间: 2023-12-29 18:14:13 浏览: 30
好的,以下是用C语言实现该程序的代码:
```c
#include <stdio.h>
#include <string.h>
#define MAX_N 10
#define MAX_NAME_LEN 20
struct Student {
int num;
char name[MAX_NAME_LEN];
int score[3];
double average;
};
int main() {
int n;
scanf("%d", &n);
struct Student stu[MAX_N];
for (int i = 0; i < n; i++) {
scanf("%d%s%d%d%d", &stu[i].num, stu[i].name, &stu[i].score[0], &stu[i].score[1], &stu[i].score[2]);
// 计算平均分
stu[i].average = 0;
for (int j = 0; j < 3; j++) {
stu[i].average += stu[i].score[j];
}
stu[i].average /= 3;
}
int max_index = 0;
for (int i = 1; i < n; i++) {
if (stu[i].average > stu[max_index].average) {
max_index = i;
}
}
printf("num:%d name:%s average:%.2f", stu[max_index].num, stu[max_index].name, stu[max_index].average);
return 0;
}
```
这个程序和上面的C++程序实现类似,只是语法有些不同。使用`struct`关键字定义了一个名为`Student`的结构体,包含学号、姓名、三门课程成绩以及平均分。输入学生信息时使用`scanf()`函数,输出最高平均分的学生信息时使用`printf()`函数。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)