c语言求二位数组行列的平均数
时间: 2023-11-24 14:51:03 浏览: 101
以下是C语言求二维数组行列平均数的示例代码:
```c
#include <stdio.h>
int main() {
float score[5][3] = {{80, 90, 70}, {85, 95, 75}, {90, 85, 80}, {95, 80, 85}, {70, 75, 90}};
float row_average[5] = {0.0, 0.0, 0.0, 0.0, 0.0};
float column_average[3] = {0.0, 0.0, 0.0};
// 计算行平均数
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 3; j++) {
row_average[i] += score[i][j];
}
row_average[i] /= 3;
}
// 计算列平均数
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 5; j++) {
column_average[i] += score[j][i];
}
column_average[i] /= 5;
}
// 输出结果
printf("每个学生的平均分为:\n"); for (int i = 0; i < 5; i++) {
printf("第%d个学生的平均分为:%f\n", i + 1, row_average[i]);
}
printf("每门课的平均分为:\n");
for (int i = 0; i < 3; i++) {
printf("第%d门课的平均分为:%f\n", i + 1, column_average[i]);
}
return 0;
}
```
阅读全文