INPUT "vvedite razmer N ", n
DIM a(n, n)
x = n
y = n + 1
num = 1
dlina = n
shag = 1
DO WHILE dlina <> 0
i = 0
DO WHILE i <> dlina
y = y - shag
a(y, x) = num
s = s + a(y, x)
num = num + 1
i = i + 1
LOOP
i = 0
dlina = dlina - 1
DO WHILE i <> dlina
x = x - shag
a(y, x) = num
s = s + a(y, x)
num = num + 1
i = i + 1
LOOP
shag = shag * (-1)
LOOP
FOR i = 1 TO n
FOR j = 1 TO n
PRINT a(i, j);
NEXT
PRINT
NEXT
PRINT "s="; s
Тестирование выполнено в программе QB64 ( Скачать )