#include <stdio.h>
float course_avg(float (*arr)[5], int row, int col, int course_id) { float sum = 0; for (int i = 0; i < row; i++) { sum += *(*(arr + i) + course_id); } return (sum / row); }
float stu_avg(float *score, int sz) { float sum = 0; for (int i = 0; i < sz; i++) { sum += *(score + i); } return (sum / sz); }
void print_stu_score(float *score, int sz) { printf("此学生的所有成绩如下:"); for (int i = 0; i < sz; i++) { printf("%.2f ", *(score + i)); } printf("\n"); }
void fail(float (*arr)[5], int row, int col) { for (int i = 0; i < row; i++) { int fail_count = 0; for (int j = 0; j < col; j++) { if (*(*(arr + i) + j) < 60) { fail_count++; } } if (fail_count > 2) { printf("%d 号学生,有两门以上课程不及格\n", i); printf("这个学生的平均成绩是:%f\n", stu_avg(*(arr + i), col)); print_stu_score(*(arr + i), col); } } }
void excellent(float (*arr)[5], int row, int col) { for (int i = 0; i < row; i++) { int course_count = 0; float num = 0; for (int j = 0; j < col; j++) { if (*(*(arr + i) + j) > 85) { course_count++; } num += arr[i][j]; } if (num / col > 90 || course_count == col) { printf("%d 号学生,真是好学生!\n", i); print_stu_score(*(arr + i), col); } } }
int main() { float score[4][5] = { {32, 48, 58, 36, 75}, {98, 70, 99, 100, 90}, {87, 88, 89, 86, 87}, {68, 98, 75, 78, 82}, }; float cour_avg_score = course_avg(score, 4, 5, 0); printf("第1门课程的平均分:%.2f\n", cour_avg_score); fail(score, 4, 5); excellent(score, 4, 5); return 0; }
|