Var a: array[1..20, 1..20] of integer;
n, m, i, j, d, rez, main_sum, line_sum, column_sum: integer;
begin
randomize;
repeat
write('Введите размеры матрицы n, m через пробел: ');
readln(n,m);
until (n in [1..20]) and (m in [1..20]);
writeln('Матрица:');
for i := 1 to n do begin
for j := 1 to m dobegin
a[i, j] := random(20) - 1;
write(a[i, j]:5);
end;
if odd(i) then writeln(' ') else writeln;
end;
main_sum := 0;
for i := 1 to n do begin
main_sum := main_sum + a [1, i];
rez := 1;
column_sum := 0;
line_sum := 0;
for j := 1 to n do begin
column_sum := column_sum + a[j, i];
line_sum := line_sum + a[i, j];
end;
if (main_sum <> column_sum) or (line_sum <> main_sum) then rez := 0;
end;
d := 0;
for i := 1 to n do d := d + a[i, n - i + 1];
if d <> main_sum then rez := 0;
if rez = 0 then
write('Квадрат не магический')
else write('Квадрат магический');
end.