#include <stdio.h>
void sum_matrix_cols(int matrix[][5], int cols_sum[3], int rows, int cols)
{
for (int j = 0; j < cols; j++) {
for (int i = 0; i < rows; i++)
cols_sum[j] += matrix[i][j];
}
}
int main()
{
int matrix[3][5] = { { 1, 2, 3, 4, 5 },
{ 1, 2, 3, 4, 5 },
{ 1, 2, 3, 4, 5 } };
int cols_sum[5] = { 0 };
int rows = sizeof matrix / sizeof matrix[0];
int cols = sizeof matrix[0] / sizeof(int);
sum_matrix_cols(matrix, cols_sum, rows, cols);
for (int i = 0; i < 5; i++)
printf("%d\n", cols_sum[i]);
return 0;
}
/*
run:
3
6
9
12
15
*/