1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
| #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; }
|