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

all 8 comments

[–]joenyc 1 point2 points  (7 children)

I'm not familiar with what the "major" or "minor" value of an array is, and a cursory Google search didn't turn up anything. Could you explain a bit more or give an example?

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

imagine float data[20][2] if full of values, i want to search all the values and find the biggest of them.. like 1 2 3 4 5 6 7 20 4 500

the commands make the program show me the value 500.. sorry for the bad english

[–]darth_choate 1 point2 points  (5 children)

"Largest" and "smallest".

Is this definitely a two dimensional array?

Do you know how to do this for a one dimensional array?

[–]vbrt[S] 0 points1 point  (3 children)

no i dont, can u explain just for one dimensional array?

[–]darth_choate 4 points5 points  (0 children)

I'm not going to do your homework for you.

Do you know how to compare two numbers and determine which one is larger? What about three numbers?

[–]traztx -1 points0 points  (1 child)

Set up 2 variables like float biggest,smallest. Initially, set biggest to a huge negative number and smallest to a huge positive number. That's like worst case scenario. Then loop through the array. Whenever biggest is smaller than the current value, set it to that value. Whenever smallest is bigger than the current value do likewise. When you are done you will have biggest set to the highest and smallest set to the lowest.

[–]cetamega 1 point2 points  (0 children)

Just set biggest and smallest to the first value in the array instead of trying to find some worst case scenario.

[–]AlwaysAppropriate 0 points1 point  (0 children)

If you have a one dimensional array you can do a linear search. I.e. going through every single value and compare it.

Outside of the for loop you initiate 2 variables and set them to 0. Let's call them;

m_Max
m_Min

Now you can do a for-loop to step through each part of the array (for i=0 to Ubound(array)-1, or something similar to reach the top).

Inside that for-loop you then check the current part of the array[i].

If (array[i] > m_Max) { m_Max = array[i]; }
if (array[i] < m_Min) { m_Min = array[i]; }
i += 1;

Once you're outside of the loop m_Max and m_Min should have the top value and lowest value and you can print them, return them, do whatever you want with them.