Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple array code

Status
Not open for further replies.

earlrainer

Programmer
Mar 1, 2002
170
IN
in delphi how do i make an array of integers, fill it with random numbers and then find the max from these numbers?

thanks
 
It's all in the Delphi help files. You just need to string the various functions together. If you get stuck with something specific then post back and we will be glad to help.

Here are some pointers:
Arrays: work out whether you need a static (fixed-size) or dynamic (variable-size) array and read the Delphi help for examples of how to implement either.

Randomization: to generate random numbers to place in the array check out Delphi's Randomize and Random functions.

Max: to find the highest random number in the array, use Delphi's Max function within a loop.

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
On the off-chance it's not a homework assignment, I'd just inspect each random number before you add it to the array and keep track of the largest one. Forget about searching the array afterwards
 
I do agree with Griffyn's assessment. Inspecting a number stream for a maximum number is much more straightforward than trying to search an array afterwards for it.

I'm sure EarlRainer will come up with the answer of this for us. But I'd be surprised if it wasn't a homework assignment - it's just too simple of a problem to not have appeared there (actually I did this one in a class once).
 
thanks for your replies guys.
just been way out of touch with delphi.
actually what i was looking for is if a DLL passes me a dynamic array with X values , what function do I use to find X. I thought it was hi-lo but guess its not
 
Use the Length function to find the size of the array. Use Low and High functions as the lower and upper bounds of the for loop.

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top