jwqwerty - 5 months ago 11

C Question

`void sum_col(int *ar, int rows)`

{

int c, r, total;

for (c = 0; c < 4; c++)

{

total = 0;

for (r = 0; r < rows; r++)

total += ar[r][c]; // error occurs

printf("%dth column sum: %d", c + 1, total);

}

}

I'm trying to define a function which prints column sums of a 2 dimensional array. But error occurs in

`total += ar[r][c]`

Answer

It appears from your code that `ar`

should be a `2-D array`

. If it is implemented as a "jagged" array then the parameter type should be `int **`

as a argument of function. like,

```
void sum_col(int **ar, int rows)
{
// function code
}
```