home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1988 / 03 / porter / porter.ls1 next >
Text File  |  1987-12-29  |  2KB  |  47 lines

  1. Program maddints;
  2.  
  3.   { This program illustrates addition of two 180 x 180 integer  }
  4.   { matrices A and B, storing the results in a similar matrix C }
  5.  
  6. Const  max = 180;       { maximum columns/rows per square array }
  7.  
  8. Type   arrayPtr = ^bigArray;
  9.        bigArray = array [1..max, 1..max] of integer;
  10.  
  11. Var    A, B, C : arrayPtr;
  12.        x, y    : word;
  13. { ------------------------------------------------------------- }
  14.  
  15. Procedure acquire (var D : arrayPtr);
  16.  
  17.   { Allocates the array on the heap and fills it with data      }
  18.   { This is a sample procedure for demo only. Replace it with   }
  19.   {  the requisite code to acquire data from an external source }
  20.  
  21. Var   r, c : word;
  22.  
  23. Begin
  24.   New (D);                                    { allocate a node }
  25.   For r := 1 to max do
  26.     For c := 1 to max do
  27.       D^ [r, c] := (r * 10) + c;  { value of each array element }
  28. End;
  29. { --------------------------- }
  30.  
  31. Begin     { main program }
  32.   Acquire (A);                             { acquire array data }
  33.   Acquire (B);
  34.   New (C);                         { set aside space for result }
  35.   For y := 1 to max do
  36.     For x := 1 to max do
  37.       C^ [y, x] := A^ [y, x] + B^ [y, x];   { add arrays into C }
  38.   Writeln ('Proof:');
  39.   Writeln ('A [1, 1] = ', A^ [1, 1]);
  40.   Writeln ('B [1, 1] = ', B^ [1, 1]);
  41.   Writeln ('C [1, 1] = ', C^ [1, 1]);
  42.   Writeln;
  43.   Writeln ('A [max, max] = ', A^ [max, max]);
  44.   Writeln ('B [max, max] = ', B^ [max, max]);
  45.   Writeln ('C [max, max] = ', C^ [max, max]);
  46. End.
  47.