求一个给定的4*5矩阵各行的元素之和
时间: 2024-06-13 21:06:50 浏览: 104
矩阵的每行之和
以下是求一个给定的4*5矩阵各行的元素之和的C语言代码:
```c
#include <stdio.h>
int main() {
int matrix[4][5] = {{1, 2, 3, 4, 5},
{6, 7, 8, 9, 10},
{11, 12, 13, 14, 15},
{16, 17, 18, 19, 20}};
int row_sum[4] = {0};
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 5; j++) {
row_sum[i] += matrix[i][j];
}
}
for (int i = 0; i < 4; i++) {
printf("第%d行元素之和为:%d\n", i + 1, row_sum[i]);
}
return 0;
}
```
阅读全文