//Pascal
var
A: array [1 .. 5, 1 .. 5] of integer;
i, j, SUM: integer;
begin
randomize;
writeln(' ***Исходная матрица***');
for i := 1 to 5 do
begin
for j := 1 to 5 do
begin
A[i, j] := random(50);
if j >= i then SUM := SUM + A[i, j];
write(A[i, j]:4);
end;
writeln;
end;
writeln;
writeln('Сумма элементов = ', SUM);
writeln;
writeln(' ***Измененная матрица***');
for i := 1 to 5 do
begin
for j := 1 to 5 do
begin
if i = j then A[i, j] := 1;
write(A[i, j]:4);
end;
writeln;
end;
readln;
end.