{ File: sommamat.pas }

{ Scopo: operazioni su matrici }

program SommaDueMatrici;
{ Calcola la matrice somma di due matrici. }

const
  NumRighe   = 2;
  NumColonne = 3;

type
  IndiceRiga    = 1..NumRighe;
  IndiceColonna = 1..NumColonne;

  TipoMatrice   = array [IndiceRiga,IndiceColonna] of integer;

var
  mat1, mat2, somma : TipoMatrice;


  procedure LeggiMatrice (var matrice : TipoMatrice);
  var
    i : IndiceRiga;
    j : IndiceColonna;

  begin { LeggiMatrice }
    for i := 1 to NumRighe do
    begin
      writeln('Riga ', i);
      for j := 1 to NumColonne do
      begin
        write('  Colonna ', j:2, ' ? ');
        readln(matrice[i,j])
      end
    end;
    writeln
  end; { LeggiMatrice }


  procedure SommaMatrici (m1, m2: TipoMatrice; var s: TipoMatrice);
  var
    i : IndiceRiga;
    j : IndiceColonna;

  begin { SommaMatrici }
    for i := 1 to NumRighe do
      for j := 1 to NumColonne do
        s[i,j] := m1[i,j] + m2[i,j]
  end; { SommaMatrici }


  procedure StampaMatrice (matrice : TipoMatrice);
  var
    i : IndiceRiga;
    j : IndiceColonna;

  begin { StampaMatrice }
    for i := 1 to NumRighe do
    begin
      for j := 1 to NumColonne do
        write(matrice[i,j]:5);
      writeln
    end
  end; { StampaMatrice }


begin { SommaDueMatrici }

  { lettura matrici }
  writeln('Immetti gli elementi della prima matrice (', NumRighe, 'x',
          NumColonne, ') !');
  LeggiMatrice(mat1);
  writeln('Immetti gli elementi della seconda matrice (', NumRighe, 'x',
          NumColonne, ') !');
  LeggiMatrice(mat2);

  { calcolo della matrice somma }
  SommaMatrici(mat1, mat2, somma);

  { stampa della matrice somma }
  writeln('La matrice somma e'':');
  StampaMatrice(mat)

end. { SommaDueMatrici }