program SommaRigheColonne;
const
NumRighe = 2;
NumColonne = 3;
type
IndiceRiga = 1..NumRighe;
IndiceColonna = 1..NumColonne;
TipoRiga = array [IndiceColonna] of integer;
TipoColonna = array [IndiceRiga] of integer;
TipoMatrice = array [IndiceRiga] of TipoRiga;
var
mat : TipoMatrice;
somma_righe : TipoRiga;
somma_colonne : TipoColonna;
i : IndiceRiga;
j : IndiceColonna;
procedure SommaRighe (matrice: TipoMatrice; var riga: TipoRiga);
var
i : IndiceRiga;
j : IndiceColonna;
begin
riga := matrice[1];
for j := 1 to NumColonne do
for i := 2 to NumRighe do
riga[j] := riga[j] + matrice[i,j]
end;
procedure SommaColonne (matrice: TipoMatrice; var colonna: TipoColonna);
var
i : IndiceRiga;
j : IndiceColonna;
begin
for i := 1 to NumRighe do
begin
colonna[i] := matrice[i,1];
for j := 2 to NumColonne do
colonna[i] := colonna[i] + matrice[i,j]
end
end;
begin
writeln('Immetti gli elementi della matrice ',
NumRighe, 'x', NumColonne, ' !');
for i := 1 to NumRighe do
begin
writeln('Riga ', i);
for j := 1 to NumColonne do
begin
write(' Colonna ', j:2, ' ? ');
readln(mat[i,j])
end
end;
writeln;
SommaRighe(mat, somma_righe);
writeln('Il vettore somma delle righe e'':');
for j := 1 to NumColonne do
writeln(' Colonna ', j, ' : ', somma_righe[j]);
writeln;
SommaColonne(mat, somma_colonne);
writeln('Il vettore somma delle colonne e'':');
for i := 1 to NumRighe do
writeln(' Riga ', i, ' : ', somma_colonne[i])
end.