200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > 【C】例9.7有n个结构体变量 内含学生学号 姓名和3门课程的成绩。要求输出平均成绩最

【C】例9.7有n个结构体变量 内含学生学号 姓名和3门课程的成绩。要求输出平均成绩最

时间:2023-02-10 01:01:44

相关推荐

【C】例9.7有n个结构体变量 内含学生学号 姓名和3门课程的成绩。要求输出平均成绩最

//有n个结构体变量,内含学生学号、姓名和3门课程的成绩。//要求输出平均成绩最高的学生的信息(包括学号、姓名、3门课程成绩和平均成绩)#include <stdio.h>#define N 3struct Student {int num;char name[20];float score[3];float aver;};int main() {//函数声明void input(struct Student stu[]);struct Student max(struct Student stu[]);void print(struct Student stud);struct Student stu[N],*p;p = stu;input(p);print(max(p));return 0;}void input(struct Student stu[]) {int i;for (i = 0; i < N; i++) {scanf_s("%d%s%f%f%f", &stu[i].num, stu[i].name,20, &stu[i].score[0], &stu[i].score[1], &stu[i].score[2]);stu[i].aver = (stu[i].score[0] + stu[i].score[1] + stu[i].score[2]) / 3;}}struct Student max(struct Student stu[]) {int i, m=0;for (i = 0; i < N; i++) {if (stu[i].aver > stu[m].aver) {m = i;}}return stu[m];}void print(struct Student stud) {printf("学号为:%d\n姓名为:%s\n三门成绩为:%f\n%f\n%f\n平均成绩为:%f\n", stud.num, stud.name, stud.score[0], stud.score[1], stud.score[2], stud.aver);}

【C】例9.7有n个结构体变量 内含学生学号 姓名和3门课程的成绩。要求输出平均成绩最高的学生的信息(包括学号 姓名 3门课程成绩和平均成绩)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。