CLS
RANDOMIZE TIMER
INPUT "vvedite n"; n
DIM a(n, n), b(n)
FOR i = 1 TO n: FOR j = 1 TO n
a(i, j) = FIX(RND * 100)
NEXT: NEXT
FOR i = 1 TO n: FOR j = 1 TO n
PRINT a(i, j);
NEXT: PRINT: NEXT
PRINT STRING$(80, 196)
FOR i = 1 TO n
b(i) = a(i, i)
NEXT
FOR i = 1 TO n
PRINT b(i);
NEXT
FOR i = 1 TO n \ 2: FOR j = 2 TO n \ 2
IF b(j) < b(j - 1) THEN SWAP b(j), b(j - 1)
NEXT: NEXT
FOR i = n \ 2 + 1 TO n: FOR j = n \ 2 + 2 TO n
IF b(j) > b(j - 1) THEN SWAP b(j), b(j - 1)
NEXT: NEXT
PRINT STRING$(80, 196)
FOR i = 1 TO n
PRINT b(i);
NEXT
Тестирование выполнено в программе QB64 ( Скачать )