Author Topic: How to find the smallest value in an array  (Read 747 times)

0 Members and 3 Guests are viewing this topic.

Offline Norbo

  • Camper
  • ***
  • Posts: 338
How to find the smallest value in an array
« on: August 20, 2008, 10:30:17 am »
Aight so i have an array [1..32] and i want to find the smallest value from this array
how do i do that?

Offline Toumaz

  • Veteran
  • *****
  • Posts: 1904
Re: How to find the smallest value in an array
« Reply #1 on: August 20, 2008, 10:47:39 am »
No clue if this is an effective way of doing it or not (or if it'll even compile; I haven't tested it), but meh!

min := 0;
min_index = 0;

for i := 1 to 32 do
    if (min_index = 0) or (array < min) then begin
        min_index := i;
        min := array;
    end;

Offline mar77a

  • Global Moderator
  • Veteran
  • *****
  • Posts: 1295
  • mad
    • random stuffs
Re: How to find the smallest value in an array
« Reply #2 on: August 20, 2008, 01:07:03 pm »
Code: [Select]
min := array[1];

for i := 2 to 32 do
    if (array[i] < min) then begin
        min := array[i];
    end;