Определить является ли данная квадратная матрица а(5,5) магическим квадратом (т.е одинаковы ли суммы чисел во всех строках, столбцах и диагоналях). в delphi.
Program abc;const a: array [1..5] of array [1..5] of integer = ((1, 15, 24, 8, 17),(9,18,2,11,25),(12,21,10,19,3),(20,4,13,22,6),(23,7,16,5,14));var i, j, x: integer; arr: array [1..12] of integer;begin
for i := 1 to 5 do begin x := 0; for j := 1 to 5 do x := x + a[i][j]; arr[i] := x; end; for i := 1 to 5 do begin x := 0; for j := 1 to 5 do begin x := x + a[j][i]; end; arr[5+i] := x; end; x := 0; for i := 1 to 5 do begin x := x + a[i][i]; end; arr[11] := x; x := 0; for i := 1 to 5 do begin x := x + a[i][6 - i]; end; arr[12] := x; for i := 1 to 12 do begin if arr[i] <> x then begin writeln('Не магический'); break; end; if i = 12 then writeln('Магический.'); end; end.
for i := 1 to 5 do begin x := 0; for j := 1 to 5 do x := x + a[i][j]; arr[i] := x; end; for i := 1 to 5 do begin x := 0; for j := 1 to 5 do begin
x := x + a[j][i]; end; arr[5+i] := x; end; x := 0; for i := 1 to 5 do begin x := x + a[i][i]; end; arr[11] := x; x := 0; for i := 1 to 5 do begin x := x + a[i][6 - i]; end; arr[12] := x; for i := 1 to 12 do begin if arr[i] <> x then begin writeln('Не магический'); break; end; if i = 12 then writeln('Магический.'); end; end.