Sign in Join
Wiki copytemporary

Revision 1 of 1, by WikiArchive on 11-4-2026. The page as it is now.

Basic Pascal Tutorial/Chapter 1/Solution

1Ha - Solution (author: Tao Yue, state: changed)

Here's one way to solve the programming assignment in the previous section.

pascal
(* Author:    Tao Yue
   Date:      19 June 1997
   Description:
      Find the sum and average of five predefined numbers
   Version:
      1.0 - original version
*)

program SumAverage;

const
   NumberOfIntegers = 5;

var
   A, B, C, D, E : integer;
   Sum : integer;
   Average : real;

begin    (* Main *)
   A := 45;
   B := 7;
   C := 68;
   D := 2;
   E := 34;
   Sum := A + B + C + D + E;
   Average := Sum / NumberOfIntegers;
   writeln ('Number of integers = ', NumberOfIntegers);
   writeln ('Number 1 = ', A);
   writeln ('Number 2 = ', B);
   writeln ('Number 3 = ', C);
   writeln ('Number 4 = ', D);
   writeln ('Number 5 = ', E);
   writeln ('Sum = ', Sum);
   writeln ('Average = ', Average)
end.     (* Main *)

From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 1/Solution", as it stood on 2022-08-20 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.