The Simula Programming Language

Average Value Example Program


Click below to go directly to a specific section:
Description | Source Code | Sample Run | Program Notes

Description

This program finds out the average value and the highest value from a list of whole numbers

Source Code

BEGIN INTEGER X, N, SUM, MAX;

IF LASTITEM THEN OUTTEXT ("NULL LIST") ELSE
BEGIN SUM:=MAX:=ININT;
N:=1;

WHILE  LASTITEM DC
BEGIN X:=ININT;
N:=N+1;
IF X > MAX THEN MAX:=X;
SUM:=SUM+X;
END;
OUTTEXT("LIST LENGTH = ");      OUTINT (N, 6);
OUTTEXT(",            HIGHEST = ");     OUTINT (MAX, 6);
OUTTEXT(",      AVERAGE = ");   OUTFIX (SUM/N, 2,, 8);

END;
OUTIMAGE;
END

Sample Run

**INPUT 1:
**OUTPUT 1:
NULL LIST

**INPUT 2:
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6
**OUTPUT 2:
LIST LENGTH=    21,     HIGHEST=        9,      AVERAGE=        4.90

Program Notes

This program has not been tested.
[BACK] [HOME]

Last modified: 6:00 P.M. on 11/20/1996