Магический квадрат с n сторон const mn = 16; var p: boolean; procedure swap(var a, b: integer); var t: integer; begin t : = a; a : = b; b : = t end; procedure createmagic(n: integer); var i, j, k, s, b, r, m: integer; a: array[1.. mn, 1.. mn] of integer; begin p : = true; if odd(n) then begin i : = 1; j : = succ(n div 2); for k : = 1 to sqr(n) do begin a[i, j] : = k; if k mod n = 0 then inc(i) else begin dec(i); inc(j); if i = 0 then i : = n; if j > n then j : = 1 end end; end else if n mod 4 = 0 then begin k : = 1; for i : = 1 to n do for j : = 1 to n do begin a[i, j] : = k; inc(k) end; j : = 2; m : = n div 2; for i : = 1 to m do for k : = 1 to m div 2 do begin if j = succ(m) then j : = 2 else if j = (m + 2) then j : = 1; s : = succ(n - i); b : = succ(n - j); swap(a[i, j], a[s, b]); swap(a[i, b], a[s, j]); inc(j, 2) end end else if n < > 2 then begin k : = 1; for i : = 1 to n do for j : = 1 to n do begin a[i, j] : = k; inc(k) end; r : = pred(n div 2) div 2; m : = n div 2; for i : = 1 to m do begin j : = i; for k : = 1 to r do begin if j > m then j : = 1; s : = succ(n - i); b : = succ(n - j); swap(a[i, j], a[s, b]); swap(a[i, b], a[s, j]); inc(j) end end; i : = 1; for k : = 1 to m do begin if j > m then j : = 1; s : = succ(n - i); swap(a[i, j], a[s, j]); inc(i); inc(j) end; i : = 1; j : = r + 2; for k : = 1 to m do begin if j > m then j : = 1; b : = succ(n - j); swap(a[i, j], a[i, b]); inc(i); inc(j) end end else p : = false; if p then begin for i : = 1 to n do begin for j : = 1 to n do write(a[i, j]: 4); writeln end end else writeln( 'do not exists' ) end; var n: integer; begin writeln('n = '); readln(n); createmagic(n); end.
Wunkamnevniki13438
20.02.2020
Var i : integer; aa : array[1..9] of integer; begin { высчитываем элементы массива } for i : = 1 to 9 do if i mod 3 = 1 then aa[i] : = (i + 5) * (i + 5) else if i mod 3 = 2 then aa[i] : = round(sqrt(aa[i-1])) else aa[i] : = aa[i-1] div aa[i-2]; { выводим значения на экран } for i : = 1 to 9 do write(aa[i], ' '); end.
kuchino09
20.02.2020
Var aa[1..1000, 1..1000] : array of integer; i, j, m, n : integer; r : boolean; begin {считываем массив} readln(m, n); for i : = 1 to m do for j : = 1 to n do read(aa[i, j]); { r равен true до первого элемента, равного 0} r : = true; i : = 0; while i < = m and r = true do begin i : = i + 1; j : = 0; while j < = n and r = true do begin j : = j + 1; if aa[i, j] = 0 then r : = false; end; end; writeln(i, ' ', j); end.