for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { // 判断学生成绩大小,如果总成绩相同则比较语文成绩,再比较学号 if (students[j].chin + students[j].math + students[j].eng > students[i].chin + students[i].math + students[i].eng || (students[j].chin + students[j].math + students[j].eng == students[i].chin + students[i].math + students[i].eng && students[j].chin > students[i].chin) || (students[j].chin + students[j].math + students[j].eng == students[i].chin + students[i].math + students[i].eng && students[j].chin
为什么我的不行明明运行成功了#include <stdio.h> #include <stdio.h> // 定义学生结构体 struct Student { int id; // 学号 int chin; // 语文成绩 int math; // 数学成绩 int eng; // 英语成绩 }; int main() { int n; // 输入学生数量 printf("请输入学生数量: "); scanf("%d", &n); // 定义并初始化存储学生信息的结构体数组 struct Student students[n]; for (int i = 0; i < n; i++) { printf("请输入第%d个学生的学号、语文成绩、数学成绩、英语成绩: ", i + 1); scanf("%d %d %d %d", &students[i].id, &students[i].chin, &students[i].math, &students[i].eng); } // 排序学生成绩 for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j
李 2024-06-18 13:54:33 |
for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { // 判断学生成绩大小,如果总成绩相同则比较语文成绩,再比较学号 if (students[j].chin + students[j].math + students[j].eng > students[i].chin + students[i].math + students[i].eng || (students[j].chin + students[j].math + students[j].eng == students[i].chin + students[i].math + students[i].eng && students[j].chin > students[i].chin) || (students[j].chin + students[j].math + students[j].eng == students[i].chin + students[i].math + students[i].eng && students[j].chin == students[i].chin && students[j].id < students[i].id)) { // 交换学生成绩 struct Student temp = students[i]; students[i] = students[j]; students[j] = temp; } } } // 输出前五名学生成绩 printf("前五名学生成绩为:\n"); for (int i = 0; i < (n < 5 ? n : 5); i++) { printf("学号:%d 语文:%d 数学:%d 英语:%d 总成绩:%d\n", students[i].id, students[i].chin, students[i].math, students[i].eng, students[i].chin + students[i].math + students[i].eng); } return 0; }
C语言程序设计教程(第三版)课后习题1.6 (C语言代码)浏览:612 |
C语言程序设计教程(第三版)课后习题10.5 (C语言代码)浏览:1484 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:805 |
字符逆序 (C语言代码)浏览:706 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:727 |
C语言程序设计教程(第三版)课后习题10.2 (C语言代码)浏览:755 |
IP判断 (C语言代码)浏览:592 |
川哥的吩咐 (C语言代码)浏览:663 |
矩形面积交 (C语言代码)浏览:1433 |
求圆的面积 (C++代码)浮点数有误差!!!浏览:724 |