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-14.p
{ Advanced Pascal Programming Language Exercises
  Dr. Thomas W. MacFarland
  advanced_pencil-14.p
}

{ The purpose of this program is to:

  1.  Demonstrate the use of an array of integer variables.

  2.  Demonstrate how elements of an array can be used in
      a math activity.

  3.  Demonstrate the construction of an addition table.

}

program Demonstrate_Arrays_5;

const Size = 7;

var Result : array[1..Size,1..Size] of integer;
    R      : integer;
    C      : integer;

begin
   for R := 1 to Size do
      for C := 1 to Size do
         Result[R, C] := R + C;

   for R := 1 to Size do begin
      for C := 1 to Size do
         write('  ', R:1, '+', C:1, ' = ', Result[R,C]:2);
      writeln;
   end;
end.  {advanced_pencil-14.p} 
%  pc PASCAL/advanced_pencil-14.p
%  a.out
  1+1 =  2  1+2 =  3  1+3 =  4  1+4 =  5  1+5 =  6  1+6 =  7  1+7 =  8
  2+1 =  3  2+2 =  4  2+3 =  5  2+4 =  6  2+5 =  7  2+6 =  8  2+7 =  9
  3+1 =  4  3+2 =  5  3+3 =  6  3+4 =  7  3+5 =  8  3+6 =  9  3+7 = 10
  4+1 =  5  4+2 =  6  4+3 =  7  4+4 =  8  4+5 =  9  4+6 = 10  4+7 = 11
  5+1 =  6  5+2 =  7  5+3 =  8  5+4 =  9  5+5 = 10  5+6 = 11  5+7 = 12
  6+1 =  7  6+2 =  8  6+3 =  9  6+4 = 10  6+5 = 11  6+6 = 12  6+7 = 13
  7+1 =  8  7+2 =  9  7+3 = 10  7+4 = 11  7+5 = 12  7+6 = 13  7+7 = 14

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

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