You need to review arrays, and also you either misunderstood the problem or else you do not know how to do what you want correctly.
The reason that your program isn't giving you the output you expected is because your array index goes out of range.
For example, an array of size 5 has 5 elements. Their indices are 0, 1, 2, 3, and 4. An index of 5 is outside of the array.
Similarly in your problem, the array has 7 (size) rows. You are trying to access values at row 7, but remember that the rows are numbered from 0 to 6.
As for how you are misunderstanding the problem, imagine that these are the values stored in your array:
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35
36 37 38 39 40 41 42
43 44 45 46 47 48 49 |
Numbers 1-7 correspond to the first row, 8-14 to the second, 15-21 to the third, etc.
If you were to call your function like so:
column(A, 7, 3)
, then if your code is correctly written, it would give you:
4 + 11 + 18 + 25 + 32 + 39 + 46 = 155
Therefore, it sums the values contained in A[0][3], A[1][3], A[2][3], ..., A[6][3].
EDIT: messed up column index