program SommaDueMatrici;
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
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;
procedure SommaMatrici (m1, m2: TipoMatrice; var s: TipoMatrice);
var
i : IndiceRiga;
j : IndiceColonna;
begin
for i := 1 to NumRighe do
for j := 1 to NumColonne do
s[i,j] := m1[i,j] + m2[i,j]
end;
procedure StampaMatrice (matrice : TipoMatrice);
var
i : IndiceRiga;
j : IndiceColonna;
begin
for i := 1 to NumRighe do
begin
for j := 1 to NumColonne do
write(matrice[i,j]:5);
writeln
end
end;
begin
writeln('Immetti gli elementi della prima matrice (', NumRighe, 'x',
NumColonne, ') !');
LeggiMatrice(mat1);
writeln('Immetti gli elementi della seconda matrice (', NumRighe, 'x',
NumColonne, ') !');
LeggiMatrice(mat2);
SommaMatrici(mat1, mat2, somma);
writeln('La matrice somma e'':');
StampaMatrice(mat)
end.