Advanced Pascal Programming Language Problems

© 1998 by Dr. Thomas W. MacFarland -- All Rights Reserved


     Instructions:   Review the following program and see if you can 
                     predict the outcome by completing a "pencil 
                     trace" of the code.  

                     Program output is provided at the end of this 
                     page.

     Compiler:       The program was prepared using Standard Pascal 
                     on a UNIX-based host computer.


% cat PASCAL/advanced_pencil-10.p
{ Advanced Pascal Programming Language Exercises
  Dr. Thomas W. MacFarland
  advanced_pencil-10.p
}

{ The purpose of this program is to:

  1.  Demonstrate the use of an array of integers.

  2.  Demonstrate the printing of individual elements of
      an array.

  3.  Demonstrate the use of downto in a loop.
}

program Demonstrate_Arrays_1;

var A,B        : integer;
    Array_Name : array[1..12] of integer;

begin
   Array_Name[1] := 5;
   writeln('Array_Element     A          B');
   writeln('------------------------------'); 
   A := 100;
   for B := 12 downto 1 do
     Array_Name[B] := B - 2;
       for B := 12 downto 2 do
       writeln(Array_Name[B]:10,  A:10,  B:10);
end.  {advanced_pencil-10.p}
%  pc PASCAL/advanced_pencil-10.p
%  a.out
Array_Element     A          B
------------------------------
        10       100        12
         9       100        11
         8       100        10
         7       100         9
         6       100         8
         5       100         7
         4       100         6
         3       100         5
         2       100         4
         1       100         3
         0       100         2

Please send comments or suggestions to Dr. Thomas W. MacFarland

There have been visitors to this page since February 1, 1999.