#i补全以下代码并求出,有3个学生, 每个学生的数据包括学号、姓名、3门J课程的成绩要求编了个函数input从键备输入3个学生数据,并编了另个函数aver输山最高分的学生的数据(包括学号、娃名、3门]课程成绩、平均分数)。 nclude<stdio.h> Hdefine N 3 struct student long int num,char name[20],int score[3],float aver; intmainO void input(struct student stu(3D;void aver(struct student stu(3D;input(stu); aver(stu);printf("\n");return 0; void input(struct student stu[3p) void aver(strucl student stuf3)
时间: 2024-04-22 19:28:40 浏览: 84
#include <stdio.h>
#define N 3
struct student {
long int num;
char name[20];
int score[3];
float aver;
};
void input(struct student stu[N]) {
int i, j;
for (i = 0; i < N; i++) {
printf("请输入第%d个学生的信息:\n", i+1);
printf("学号:");
scanf("%ld", &stu[i].num);
printf("姓名:");
scanf("%s", stu[i].name);
for (j = 0; j < 3; j++) {
printf("请输入第%d门课程的成绩:", j+1);
scanf("%d", &stu[i].score[j]);
}
}
}
void aver(struct student stu[N]) {
int i, j;
float max_aver = 0;
int max_index = 0;
for (i = 0; i < N; i++) {
float sum = 0;
for (j = 0; j < 3; j++) {
sum += stu[i].score[j];
}
stu[i].aver = sum / 3.0;
if (stu[i].aver > max_aver) {
max_aver = stu[i].aver;
max_index = i;
}
}
printf("最高分的学生信息:\n");
printf("学号:%ld\n", stu[max_index].num);
printf("姓名:%s\n", stu[max_index].name);
printf("成绩:");
for (j = 0; j < 3; j++) {
printf("%d ", stu[max_index].score[j]);
}
printf("\n");
printf("平均分数:%f\n", stu[max_index].aver);
}
int main() {
struct student stu[N];
input(stu);
aver(stu);
return 0;
}
阅读全文