Дана квадратная матрица А[1..4,1..4].Нужно найти сумму элементов главной диагонали — Pascal(Паскаль)

uses crt;
const n = 4;
var a : array [1..n,1..n] of integer;
i, j, s : integer;
begin
 clrscr;
 randomize;
 for i := 1 to n do
  for j := 1 to n do
   a[i,j] := random(20);
 
  for i := 1 to n do
   begin
    for j := 1 to n do
     begin
      write(a[i,j]:3);
     end;
    writeln;
    end;
   for i := 1 to n do
    for j := 1 to n do
     if (i = j) then
      s := s + a[i,j];
   writeln('Summa = ',s);
  readln;
end.

Leave a Comment