{The index to all of Carl Drott's Pascal examples is at:}
{ http://drott.cis.drexel.edu/CommandFinder.html }
{Here we go again with arrays. This is the same sort program that we }
{did in the previous example but using array variables. At first the }
{names of the variables like "nums[counter + 1]" will seem very }
{strange. You may also wonder about the FOR loop inside of a FOR loop. }
{It works but why did I do it. The answer is so that I can sort more }
{than three numbers. See the next example.}
{}
program Sort3 (input, output);
{ requests three numbers and sorts them in descending order}
type
NumArrayType = array[1..3] of integer;
var
nums: NumArrayType;
counter, again: integer;
procedure Transpose (var first, second: integer);
{switches the contents of the two arguments}
var
TPtemp: integer;
begin
TPtemp := first;
first := second;
second := TPtemp;
end; { Proc Transpose}
begin {main program -- sort3}
Writeln('three numbers please');
Readln(nums[1], nums[2], nums[3]);
for again := 1 to 2 do
begin
for counter := 1 to 2 do
begin
if nums[counter + 1] > nums[counter] then
transpose(nums[counter + 1], nums[counter]);
end;{counter fron 1 to 2}
end;{again from 1 to 2}
writeln('done sorting');
writeln(nums[1], nums[2], nums[3]);
end. {sort3}