C语言综合问题:输入5个学生的姓名、学号和5门课成绩计算每个学生的总分和平均分并按从高到低排序

2024-11-01 20:34:25
推荐回答(2个)
回答(1):

定义一个结构体
struct student
{
char *name;//姓名
int num[10];//学号
int scor[5];//5门课成绩
int average;//平均成绩
};
用student定义5个变量,再操作应该就很简单了

回答(2):

#include typedef struct _student{ int id; char name[8]; float score1; float score2; float score3; float score4; float score5; float score_total; float score_avg;}student; int student_swap(student* s1, student* s2){ //Add your code here return 0;} float score_sum(student* s, int s_size){ float sum = 0.0; sum = sum + s->score1; sum = sum + s->score2; sum = sum + s->score3; sum = sum + s->score4; sum = sum + s->score5; return sum;} float score_avg(student* s, int s_size){ float sum = 0.0; sum = score_sum(s, s_size); return sum/s_size;
} int student_sort(student s[], int s_size){ for(int n1=0;n1