We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#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); 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:
No branches or pull requests
The text was updated successfully, but these errors were encountered: