You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
int main() {
int n; // 学生人数
printf("请输入学生人数:");
scanf("%d", &n);
Student students[n]; // 学生数组
for (int i = 0; i < n; i++) {
printf("请输入第%d个学生的学号和成绩:", i + 1);
scanf("%d%f", &students[i].studentID, &students[i].score);
}
qsort(students, n, sizeof(Student), compare);
printf("按成绩由高到低的顺序输出学生的学号和成绩:\n");
for (int i = 0; i < n; i++) {
printf("学号:%d,成绩:%.2f\n", students[i].studentID, students[i].score);
}
float sum = 0;
int count = 0;
for (int i = 0; i < n; i++) {
sum += students[i].score;
if (students[i].score < 60) {
count++;
}
}
float average = sum / n;
printf("平均成绩:%.2f\n", average);
printf("不及格学生人数:%d\n", count);
return 0;
}
The text was updated successfully, but these errors were encountered:
#include <stdio.h>
typedef struct {
int studentID;
float score;
} Student;
int compare(const void *a, const void *b) {
Student *studentA = (Student *)a;
Student *studentB = (Student *)b;
if (studentA->score < studentB->score) {
return 1;
} else if (studentA->score > studentB->score) {
return -1;
} else {
return 0;
}
}
int main() {
int n; // 学生人数
printf("请输入学生人数:");
scanf("%d", &n);
}
The text was updated successfully, but these errors were encountered: