program ProdMatrici;
const
N = 3;
type
TipoMatrice = array[1..N, 1..N] of integer;
var
mat1, mat2, mat3 : TipoMatrice;
risposta: char;
procedure LeggiMat (var m: TipoMatrice);
var
i, j : 1..N;
begin
for i := 1 to N do
begin
write(' riga ', i : 2, ' ');
for j := 1 to N do
read(m[i, j]);
end;
readln
end;
procedure StampaMat (var m: TipoMatrice);
var
i, j : 1..N;
begin
for i := 1 to N do
begin
for j := 1 to N do
write(m[i, j] : 4);
writeln
end
end;
procedure Prodotto (a, b: TipoMatrice; var c: TipoMatrice);
var
i, j,
k : 1..N;
begin
for i := 1 to N do
for j := 1 to N do
begin
c[i, j] := 0;
for k := 1 to N do
c[i,j] := c[i,j] + a[i,k] * b[k,j];
end;
end;
begin
writeln('inizio programma');
writeln('vuoi moltiplicare due matrici? (s/n) ');
repeat
readln(risposta);
if (risposta <> 's') and (risposta <> 'n') then
writeln('!!! '' s '' oppure '' n '', per favore!!!');
until (risposta = 's') or (risposta = 'n');
while (risposta = 's') do
begin
writeln('lettura prima matrice');
LeggiMat(mat1);
writeln('lettura seconda matrice');
LeggiMat(mat2);
writeln;
writeln('prima matrice letta:');
StampaMat(mat1);
writeln;
writeln('seconda matrice letta:');
StampaMat(mat2);
writeln;
writeln('matrice prodotto:');
Prodotto(mat1, mat2, mat3);
StampaMat(mat3);
writeln('vuoi moltiplicare due matrici? (s/n) ');
repeat
readln(risposta);
if (risposta <> 's') and (risposta <> 'n')
then writeln('!!! '' s '' oppure '' n '', per favore!!!');
until (risposta = 's') or (risposta = 'n');
end;
readln
end.