1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'C' started by won212, Mar 7, 2012.

  1. won212

    won212 New Member

    Joined:
    Mar 3, 2012
    Messages:
    17
    Likes Received:
    2
    Trophy Points:
    0
    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.
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    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?
     
  3. won212

    won212 New Member

    Joined:
    Mar 3, 2012
    Messages:
    17
    Likes Received:
    2
    Trophy Points:
    0
    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].
     
  4. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    OK, but post your code as well, because I can't see where you went wrong if I can't see your code.
     
  5. won212

    won212 New Member

    Joined:
    Mar 3, 2012
    Messages:
    17
    Likes Received:
    2
    Trophy Points:
    0
    Hi sorry, manage to solve this afternoon, thanks for helping anyway! ^^
     

Share This Page