вычисление суммы элементов главной диагонали квадратной матрицы (в Паскале)
var a: array[1..4, 1..4] of integer; i, j, s, n: integer;begin for i := 1 to 4 do begin for j := 1 to 4 do begin a[i, j] := random(10); write(a[i, j], ' '); inc(n); if(n mod 4 = 0) then writeln; end; s := s + a[i, i]; end; writeln(s);end.
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
var
a: array[1..4, 1..4] of integer;
i, j, s, n: integer;
begin
for i := 1 to 4 do begin
for j := 1 to 4 do begin
a[i, j] := random(10);
write(a[i, j], ' ');
inc(n);
if(n mod 4 = 0) then writeln;
end;
s := s + a[i, i];
end;
writeln(s);
end.