TOPS-20 PASCAL Language Manual - Bitsavers
TOPS-20 PASCAL Language Manual - Bitsavers
TOPS-20 PASCAL Language Manual - Bitsavers
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
PROCEDURES AND FUNCTIONS<br />
As a result of this call, the list of integers is written in the array<br />
ARR. The value of this array is then returned to the program unit<br />
that called the procedure READ WRITE.<br />
Example 2<br />
PROCEDURE MIN_MAX_AVG (VAR Miny Max : Ran~e;<br />
VAR Avg : REAL; A : List);<br />
VAR Sum, NMax~ NMin~ J : INTEGER;<br />
BEGIN<br />
M3X := Ael); Min:= Max; Sum:= Max;<br />
NMax := 1; NMin:= 1;<br />
FOR J := 2 TO NUMBER DO<br />
BEGIN<br />
Sum := Sum + A[JJ~<br />
IF A[J) > Max THEN<br />
BEGIN Max := AeJJ;<br />
NMa>: : =:: 1<br />
END<br />
ELSE IF A[JJ = Max THEN<br />
NMax := NMax + 1;<br />
IF AEJJ < Min THEN<br />
BEGIN Min := A[J);<br />
NMin !:=: 1<br />
END<br />
ELSE IF A[JJ<br />
Min THEN<br />
NMin : :~: NMin + 1<br />
END;<br />
AVG := Sum/NUMBER;<br />
WF~ I TELN;<br />
WRITELN('Maximum =',Max:4,', occurring',NMax:4, , times');<br />
WFnTELN;<br />
WRITELN('Minimuffi =', Min:4,', occurring', NMin:4,' times');<br />
WFnTELN;<br />
WRITELN ('Average value (truncated) =', TRUNC(Avg):10);<br />
WRITELN ('Average value ='r Avg : <strong>20</strong>)<br />
END;<br />
This procedure computes the minimum, maximum, and average values in<br />
array A. It also counts the number of times the minimum and maximum<br />
values occurred, and stores those numbers in NMin and NMax. The<br />
WRITELN statements print the results of each of those computations.<br />
Min, Max, and Avg are formal variable parameters. Their values, as<br />
assigned in the procedure MIN_MA.X_AVG, are returned to the calling<br />
program unit and can be used for further computations in the program.<br />
A is specified as a value parameter because its value does not change<br />
in the procedure.<br />
The following is a valid procedure call to the procedure:<br />
The values of the formal parameters Min, Max, and Avg are returned to<br />
the actual parameters Minimum, Maximum, and Average, which were<br />
defined in the main block of the program.<br />
6-31