#include <stdio.h>
#include <stdlib.h>
typedef struct {
int id; // 学生ID
char name[50]; // 学生姓名
float scores[SUBJECT_COUNT]; // 科目成绩数组,SUBJECT_COUNT是科目数量
} Student;
// 计算及格人数
int calculatePassCount(Student students[], int n, float passingGrade) {
int passCount = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < SUBJECT_COUNT; ++j) {
if (students[i].scores[j] >= passingGrade) {
passCount++;
break; // 只要一门课及格就认为该学生及格
}
}
}
return passCount;
}
// 统计分析函数
void analyze_scores(Student students[], int n, float passingGrade) {
float total_grade = 0.0f;
float max_score = students[0].scores[0];
float min_score = students[0].scores[0];
int pass_count = 0;
// 计算总分、最高分、最低分
for (int i = 0; i < n; ++i) {
for (int j = 0; j < SUBJECT_COUNT; ++j) {
total_grade += students[i].scores[j];
if (students[i].scores[j] > max_score) {
max_score = students[i].scores[j];
}
if (students[i].scores[j] < min_score && students[i].scores[j] != 0.0f) {
min_score = students[i].scores[j];
}
}
// 按照每名学生至少有一门课及格来计算及格率
if (calculatePassCount(&students[i], 1, passingGrade) > 0) {
pass_count++;
}
}
float average_score = total_grade / (n * SUBJECT_COUNT);
float pass_rate = (float) pass_count / n * 100.0f;
printf("总分: %.2f\n", total_grade);
printf("平均分: %.2f\n", average_score);
printf("最高分: %.2f\n", max_score);
printf("最低分: %.2f\n", min_score);
printf("及格率: %.2f%%\n", pass_rate);
}
int main() {
const int STUDENT_COUNT = 100; // 假设有100名学生
const int SUBJECT_COUNT = 5; // 假设有5门科目
const float PASSING_GRADE = 60.0f; // 假设及格线为60分
// 初始化学生数据...
analyze_scores(students, STUDENT_COUNT, PASSING_GRADE);
return 0;
}