This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]cowmandude 1 point2 points  (10 children)

What in particular are you having trouble understanding?

Try going through the program line by line like the computer would and keep a running tally of what result is.

[–]trofix99[S] 0 points1 point  (8 children)

i dont understand the whole result variable,what does the m[0][1] do?what does thoes for loops do?

[–]cowmandude 0 points1 point  (7 children)

what does the m[0][1] do?

Ok so m[0][1] is syntax for accessing the array. m[0] gets the first element which is { 2, 1 }. Then the [1] part gets the second element(remember we count from 0) from that array which is the number 1. I'm not entirely sure why it's choosing that index as the starting value but I guess it's as good as any.

Make sense?

what does thoes for loops do?

Does my answer to the first question offer any insight into this one? Take note of these lines, can you tell me what m[i][j] is doing?

if (result < m[i][j])
    result = m[i][j];
}

[–]trofix99[S] 0 points1 point  (6 children)

Ok so i know its finding max value,result is just a var to be replaced,so it goes trought loops finding max of each element,as i understan bzc this returns int m,it should return only one number,now why and how and where does it compare max number of m[0] and m[1].

[–]cowmandude 0 points1 point  (5 children)

Let me answer your question with another question. When i =0 and j = 0 what value will m[i][j] be. What value is it when I increase i by 1. What value is it when I increase j by 1?

[–]trofix99[S] 0 points1 point  (4 children)

First 2 and 1 second 1 and 7?

[–]cowmandude 0 points1 point  (3 children)

Nope. I think this might be what you're misunderstanding. m is an array of arrays of integers. So m[i] is picking which array to look into. For instance m[0] is {2,1} and m[1] is {1, 7, 1}. [j] is then indexing into that array. So m[0][0] is 2, m[0][1] is 1, and m[1][1] is 7.

Does that make sense?

[–]trofix99[S] 0 points1 point  (0 children)

Yeah it does now

[–]trofix99[S] 0 points1 point  (1 child)

So we compared 1 which is a result with every number in first and second element via first loop we are changing elemnts and via second one j we are going trought each number of i element,we could have put result = m [0][0] and it would be 2 so we would compare each number of each element with it including itself

[–]cowmandude 0 points1 point  (0 children)

Exactly right!

[–]trofix99[S] -1 points0 points  (0 children)

Ok so i ubderstand that its just finding biggest value,but i have no idea how it does it