Posted: Tue Apr 07, 2015 9:58 am Post subject: Finding the max/min number of an array?
Creating a program for class, need to put 10 real numbers in an array and find the largest and smallest number from it.
One idea I had was to create a for loop with if statements in it that filtered out the other numbers, but I feel like that is too complicated to be correct.
Sponsor Sponsor
Dreadnought
Posted: Tue Apr 07, 2015 11:16 am Post subject: Re: Finding the max/min number of an array?
It might help to think about how you might do this yourself if you were given a list of numbers. Can you get the computer to use the same approach?
Also, if 10 numbers seems too simple, consider what you would do if you were asked to find the maximum or minimum for a list of 100 or 1000 numbers.
Clayton
Posted: Tue Apr 07, 2015 2:37 pm Post subject: RE:Finding the max/min number of an array?
To add on to what Dreadnought is saying. How would you do this if you had every number on it's own piece of individual paper, and you only got to see one number at a time?
gayden
Posted: Wed Apr 08, 2015 9:05 am Post subject: Re: RE:Finding the max/min number of an array?
Clayton @ Tue Apr 07, 2015 2:37 pm wrote:
To add on to what Dreadnought is saying. How would you do this if you had every number on it's own piece of individual paper, and you only got to see one number at a time?
What this makes me think of doing is something like this:
if num1 > num2 and num1 > num3 and num1 > num4, etc.
but doing that for 10 numbers will give me a stupid amount of code. Is there a way I can use a function like max but for more than comparing two numbers?
Insectoid
Posted: Wed Apr 08, 2015 9:50 am Post subject: RE:Finding the max/min number of an array?
You've got an array. Arrays play really nicely with for loops. You might want to take advantage of that.
gayden
Posted: Thu Apr 09, 2015 8:59 am Post subject: Re: RE:Finding the max/min number of an array?
Insectoid @ Wed Apr 08, 2015 9:50 am wrote:
You've got an array. Arrays play really nicely with for loops. You might want to take advantage of that.
Think I got it.
Turing:
for j :lower(range).. upper(range) if maxi < range (j)then
maxi := range (j) endif if mini > range (j)then
mini := range (j) endif endfor %Where maxi := minint and mini := maxint