CLS
INPUT "Vvedite kol-vo stolbcov:", xl
INPUT "Vvedite kol-vo strok:", yl
DIM X(xl, yl) AS INTEGER, Min1, Min2
RANDOMIZE TIMER
' Zapolnenie matritsi
FOR iy = 1 TO yl: FOR ix = 1 TO xl
X(ix, iy) = (RND * 101) - 50
NEXT: NEXT
' Vivod iskhodnoi matritsi
PRINT "Ishodnaya:"
FOR iy = 1 TO yl: FOR ix = 1 TO xl
PRINT X(ix, iy);
NEXT: PRINT: NEXT
' Poisk minimalnikh elementov v stolbtsakh i zamena iskhodya iz etogo
FOR ix2 = xl - 1 TO 1 STEP -1
FOR ix = 1 TO ix2
' Poisk minimalnikh v sosednikh stolbtsakh
Min1 = X(ix, 1): Min2 = X(ix + 1, 1)
FOR iy = 1 TO yl
IF X(ix, iy) < Min1 THEN Min1 = X(ix, iy)
IF X(ix + 1, iy) < Min2 THEN Min2 = X(ix + 1, iy)
NEXT
' Zamena sosednikh stolbtsov
IF Min1 > Min2 THEN
FOR iy = 1 TO yl: SWAP X(ix, iy), X(ix + 1, iy): NEXT
END IF
NEXT
NEXT
' Vivod rezultata
PRINT "Novaya:"
FOR iy = 1 TO yl: FOR ix = 1 TO xl
PRINT X(ix, iy);
NEXT: PRINT: NEXT
Тестирование выполнено в программе QB64 ( Скачать )