How do i compare row and column in 2D array?

won212's Avatar, Join Date: Mar 2012
Go4Expert Member
Hi do any expert/programmer know how can I compare the same row with same column to derive the maximum value? For examples, column 1 will be comparing with row 1, column 2 will be comparing with row 2, column 3 with row 3 and so on...

I did some c++ coding but it didn't works.

I guess I do not know yet to use what method for comparing same column and same row together, what code can ensure this?

By the way, my error is I have a 5x5 array, my first to fourth looping manage to get the correct maximum value. How ever, for the last, 5th position which is comparing array[4][0] with [0][4], I got the correct maximum value but did not manage to get the correct position [][] of the maximum value.

Thanks.
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
How exactly didn't it work? Post your code. What input did you give (if relevant); what output did you get, and what output did you expect?
won212's Avatar, Join Date: Mar 2012
Go4Expert Member
Hi for example I wanted it to print the maximum value as well as the the position.

For example, this is my 5x5 matrix.

1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 1

To compare 1st row with 1st column and as follow,

my result should shown:

[4][0] - 21
[4][1] - 22
[4][2] - 23
[4][3] - 24
[3][4] - 24, it should have printed [4][3].
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
OK, but post your code as well, because I can't see where you went wrong if I can't see your code.
won212's Avatar, Join Date: Mar 2012
Go4Expert Member
Hi sorry, manage to solve this afternoon, thanks for helping anyway! ^^