Archived

This topic is now archived and is closed to further replies.

How do i ...

This topic is 5179 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

create a programm that always select the smallest number? maybe i got 4 numbers: 16 48 67 98 How can i make that the programm select the smallest number, here 16. the programm is writen in visial basic. thanks for your help

Share this post


Link to post
Share on other sites
The algorithim to do that is independant of the language being used to write the program.

Basically, just do this:

1. Assume the first element is the smallest
2. Save this to a variable.
3. Loop through the array comparing whether it''s smaller then
the value in your variable.
if it is then reassign variable to equal current array element.

4. return variable





--{You fight like a dairy farmer!}

Share this post


Link to post
Share on other sites
I''ll pseudo that for you:

var [ Temp ] = array[0] ;

loop through [ number of elements ] with [ var i ] start at [ 1 ] //skip the first
{
if ( array[ i ] < Temp )
Temp = array[ i ];
}

return Temp;

--
You''re Welcome,
Rick Wong
- sitting in his chair doing the most time-consuming thing..

Share this post


Link to post
Share on other sites