QZHY-HTX / Data-Structure

泉州海洋职业学院信息工程学院2023-2024学年第二学期数据结构课程仓库
MIT License
6 stars 9 forks source link

潘梁坤 2302580016 #13

Open GGtired opened 7 months ago

GGtired commented 7 months ago

include

struct Student { int id; float score; };

bool compareScores(const Student &a, const Student &b) { return a.score > b.score; }

include< stdio.h>

// 定义结构体 struct stu //定义了一个结构体 struct stu,包括学生的学号和成绩。 { char id[20]; float score; }; int main(){ //在 main 函数中,创建了一个包含5个学生的数组,每个学生有学号和成绩。 struct stu student[5] ={ {“10001”,98},{“10002”,83},{“10003”,44},{“10004”,34},{“10005”,67} }; const int n = 5; struct stu temp;// struct stu temp 是用来交换学生信息的临时变量。 int i,j,k; for(i = 0;I<n-1;i++){ k = i; for(j = i + 1;J<N;j++){ if(student[j].score > student[k].score) k = j; temp = 学生[k]; student[k] = 学生[i]; student[i] = 临时; } }

//计算平均数和不及格人数 float avg,sum;avg:平均数;sum: int lower_stu_num = 0;lower_stu_num: for(i = 0;i<n;i++){ sum += student[i].score; if(student[i].score <=60.0) lower_stu_num +=1; } 平均 = 总和 / n;

输出 for(i = 0;i<n;i++) printf(“%s %.2f\n”,student[i].id,student[i].score); printf(“%.2f %d”,平均,lower_stu_num); return 0; }

QZHY-HTX commented 7 months ago