MODULE SumAndAverage; FROM InOut IMPORT ReadInt, WriteString, WriteLn, WriteInt, OpenInput, OpenOutput, CloseInput, CloseOutput, Done; VAR N:INTEGER; X:INTEGER; SUM:INTEGER; AVERAGE:INTEGER; BEGIN WriteString('Enter the names of the output, input files'); WriteLn; OpenOutput("OUT"); IF NOT Done THEN WriteString('Output file cannot be opened'); WriteLn; HALT; END; OpenInput("IN"); IF NOT Done THEN CloseOutput; WriteString('Input file cannot be opened'); WriteLn; HALT; END; N:=0; SUM:=0; ReadInt(X); WHILE Done DO WriteInt(X,3); WriteLn; N:=N+1; SUM:=SUM+X; ReadInt(X); END; WriteString('The Sum is '); WriteInt(SUM, 1); WriteLn; AVERAGE:=SUM DIV N; WriteString('The Average is '); WriteInt(AVERAGE, 1); WriteLn; CloseOutput; CloseInput; END SumAndAverage.
0 1 2 3 4 5 6 7 8 9 10 The Sum is 55 The Average is 5