NASutils Knowledge BaseUnofficialPolski

Pascal · lesson 13 of 30 · Data, functions and the command lineKeep many values

Low and High give the first and the last index of an array, Length the number of its elements.

Programming on the NAS › Pascal in 30 lessons

13-arrays.pas Download 13-arrays.pas

program Arrays;
const
  Temp: array[1..4] of Integer = (38, 39, 53, 44);
var
  I, Sum, Hot: Integer;
begin
  Sum := 0;
  Hot := 1;
  for I := Low(Temp) to High(Temp) do
  begin
    WriteLn('disk ', I, ': ', Temp[I], ' C');
    Sum := Sum + Temp[I];
    if Temp[I] > Temp[Hot] then
      Hot := I;
  end;
  WriteLn('average: ', Sum / Length(Temp):0:1);
  WriteLn('the warmest is disk ', Hot);
end.

Terminal

$ ./13-arrays
disk 1: 38 C
disk 2: 39 C
disk 3: 53 C
disk 4: 44 C
average: 43.5
the warmest is disk 3

Exercise

Find the lowest temperature too.