Pascal was developed by Niklaus Wirth (pronounced “Virt”) in the late 1960s and early 1970s. The goal was to produce a language that could be implemented easily on a variety of computers and that would provide students with a model teaching language. That is to say, Pascal is full of features that encourage well-written and well-structured programs. Indeed, many universities teach Pascal to their computer science students as a first language. Pascal has also migrated to the personal computer arena, first with Borland’s Turbo Pascal and more recently with Borland’s visual programming environment called Delphi.

For contrast, here is how our program to compute the average would look in Pas-cal. Text contained within curly braces ({}) are comments that are ignored by the computer:

{ Pascal program to compute the average of a set of at most 100 numbers } program average (input, output); { Declare some variables } var Num, i : integer; Ave, Sum, NextNum : real; begin { Ask for the number of numbers } writeln('Enter the number of numbers'); readln(Num); { If Num is between 1 and 100 then proceed } if ((Num > 0 ) and (Num <= 100)) then begin Sum := 0; { Loop to collect the numbers to average } for i := 1 to Num do begin { Ask for next number } writeln('Enter next number'); readln(NextNum); { Add the number to the running sum } Sum := Sum + NextNum; end { Compute the average } Ave := Sum / Num; { Display the average } writeln('The average is: ', Ave); end end

Start Free Trial

No credit card required