Implementation (algorithm specification)Examples for finding minimum

Algorithms are created to allow users to tell a computer how to solve a problem. Understanding how to construct five of the most common algorithms is a critical skill for budding software developers.

Part ofComputing ScienceSoftware design and development

Examples for finding minimum

Visual Studio 2010 (Similar to VB5, VB6 and Subsequent Visual Basic.NET languages)

In this example it is presumed that the array has already been populated.

A list box is used to output the minimum value. It is possible to use a different object for output.

minimum = testscore[0]
For counter = 1 To 9
If testscore[counter] ˂ minimum Then
minimum = testscore[counter]
End If
Next
ListBox1.Items.Add ("The minimum value was " & minimum)

LiveCode

Remember - Live code will index from 1 rather than 0!

In this example it is presumed that the array has already been populated.

put testscore[1] into minimum
repeat with loop = 2 to 10
if testscore[loop] ˂ minimum then
put testscore [loop] into minimum
End if
end repeat
put “The minimum value was" &&minimum&& into field "output"

Python – Version 3.x

In this example it is presumed that the array has already been populated.

minimum = testscore[0]
for counter in range (1, 10):
if testscore[counter] ˂ minimum:
minimum = testscore[counter]
print ("The minimum value was ", minimum)

Java

In this example it is presumed that the array has already been populated.

minimum=testscore[0];
for(int counter=1;counter˂10;counter++)
{
if(testscore[counter]˂minimum)
{
minimum=testscore[counter];
}
}
System.out.println("The minimum value was " + minimum);

True BASIC

Remember – True BASIC will index from 1 rather than 0!

In this example it is presumed that the array has already been populated.

LET minimum = testscore(1)
FOR counter = 2 to 10
IF testscore(counter) ˂ minimum THEN
minimum = testscore (counter)
END IF
NEXT counter
PRINT "The minimum value was "; minimum

Xojo (Formerly REALbasic)

In this example it is presumed that the array has already been populated.

A static text box called ‘mintext’ has been used to output the minimum value.

minimum = testscore(0)
For counter = 1 to 9
If testscore(counter)˂minimum Then
minimum = testscore(counter)
End If
Next
mintext.text = “The minimum value was ” + minimum

Pascal

In this example it is presumed that the array has already been populated.

begin
minimum:=testscore[0];
For counter := 1 to 9 do
begin
if testscore[counter] ˂ minimum then
minimum:=testscore[counter];
end;
writeln(output, 'The minimum value was ', minimum);
end.

Comal

In this example it is presumed that the array has already been populated.

minimum% := testscore% (0)
FOR counter%:= 1 TO 9 DO
IF testscore% (counter%) ˂ minimum% THEN
minimum% := testscore% (counter%)
ENDIF
NEXT
PRINT “The minimum value was ”, minimum%