用c++写一个代码:有三个学生四门课的成绩,求每个学生的平均分,每门课的平均分 数学 英语 化学 物理 张三 92 85 68 75 李四 54 88 98 45 王五 61 79 81 40
时间: 2024-02-10 20:45:11 浏览: 69
好的,以下是您要求的代码:
```
#include <stdio.h>
int main() {
int math_score[3] = {92, 54, 61};
int english_score[3] = {85, 88, 79};
int chemistry_score[3] = {68, 98, 81};
int physics_score[3] = {75, 45, 40};
int sum_math = 0, sum_english = 0, sum_chemistry = 0, sum_physics = 0;
for (int i = 0; i < 3; i++) {
sum_math += math_score[i];
sum_english += english_score[i];
sum_chemistry += chemistry_score[i];
sum_physics += physics_score[i];
printf("Student %d average score: %.2f\n", i + 1, (float)(math_score[i] + english_score[i] + chemistry_score[i] + physics_score[i]) / 4);
}
printf("Math average score: %.2f\n", (float)sum_math / 3);
printf("English average score: %.2f\n", (float)sum_english / 3);
printf("Chemistry average score: %.2f\n", (float)sum_chemistry / 3);
printf("Physics average score: %.2f\n", (float)sum_physics / 3);
return 0;
}
```
希望对您有帮助。
阅读全文