home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
MBUG
/
MBUG003.ARC
/
JRTPAS-1.LBR
/
JRT37.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1979-12-31
|
1KB
|
40 lines
{Program 6.1
find the largest and smallest number in a given list}
Program minmax;
const n = 20;
var i, u, v, min, max : integer;
a : array[ 1..n ] of integer;
{assume that at this point in the program, array a
contains the values 35 68 94 7 88 -5 -3 12 35 9
-6 3 0 -2 74 88 52 43 5 4}
begin
{for ease of testing, I will fill the array for you}
a[1]:=35;a[2]:=68;a[3]:=94;a[4]:=7;a[5]:=88;a[6]:=-5;
a[7]:=-3;a[8]:=12;a[9]:=35;a[10]:=9;a[11]:=-6;a[12]:=3;
a[13]:=0;a[14]:=-2;a[15]:=74;a[16]:=88;a[17]:=52;a[18]:=43;
a[19]:=5;a[20]:=4;
min := a[ 1 ]; max := min; i := 2;
while i < n do
begin
u := a[ i ]; v := a[ i + 1 ];
if u > v then
begin
if u > max then max := u;
if v < min then min := v;
end else
begin
if v > max then max := v;
if u < min then min := u;
end;
i := i + 2
end;
if i = n then
if a[ n ] > max then max := a[ n ]
else if a[ n ] < min then min := a[ n ];
writeln( max, min )
end.