Anonymous     Text only     31 Jan 2013
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65``` ```program Project2; {\$APPTYPE CONSOLE} uses SysUtils; var k, n, i, j, starti, startj: integer; w: array[1..100, 1..100] of integer; procedure vverh(x, y: integer);forward; procedure vniz(a, b: integer);forward; procedure vverh; begin while true do begin w[x, y] := k; inc(k); dec(x); inc(y); if (x < 1) or (y > n) then break; end; if (k <> sqr(n) - 1) and (y > n) then vniz(x + 2, y - 1) else if (k <> sqr(n) - 1) and (x < 1) then vniz(x + 1, y); end; procedure vniz; begin while true do begin w[a, b] := k; inc(k); inc(a); dec(b); if (a > n) or (b < 1) then break; end; if (k <> sqr(n) - 1) and (b < 1) then vverh(a, b + 1) else if (k <> sqr(n) - 1) and (a > n) then vverh(a - 1, b + 2); end; begin reset(input, 'input.txt'); rewrite(output, 'output.txt'); readln(n); w[1, 1] := 1; w[n, n] := sqr(n); k := 2; starti := 2; startj := 1; vverh(starti, startj); for i := 1 to n do begin for j := 1 to n do write(w[i, j]); writeln; end; end. ```