Open GitHubZian opened 7 months ago
任务要求: 1.输出全部同学的学号和某一门课程的考试成绩 2.将该课程的成绩按高到低排序 3.求平均成绩和不及格学生的人数。 最后调用main(),调用以上算法从高到低的次序输出学生的学号和相应的成绩,输出平均成绩和不及格学生人数 */ #include<stdio.h> // 定义结构体 struct stu { char id[20]; float score; }; int main(){ struct stu student[5] ={ {"10001",98},{"10002",83},{"10003",44},{"10004",34},{"10005",67} }; const int n = 5; ////n为同学数量 设为5 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 = student[k]; student[k] = student[i]; student[i] = temp; } } //计算平均数和不及格人数 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; } avg = sum / n; // 输出 for(i = 0;i<n;i++) printf("%s %.2f\n",student[i].id,student[i].score); printf("%.2f %d",avg,lower_stu_num); return 0; } // ****一些激动的电报声 void zibi(){ printf("人生苦短,(哭泣)不想碰这玩意了"); }
第N次提交,被网卡制裁
good job
作业展示
第N次提交,被网卡制裁