' Инициализация и ввод данных
DEFINT A-Z
CLS
Re: PRINT "Vvedite kol-vo elementov"
INPUT "v stoke kvadratnoj matrici: ", n
DIM M(n, n)
IF n <= 1 GOTO Re
' Вычисляем величину цикла
K = (n - 1) * 4
' Вывод исходной матрицы
PRINT STRING$(80, 196)
FOR iy = 1 TO n: FOR ix = 1 TO n
M(ix, iy) = RND * 100
LOCATE , ix * 3: PRINT M(ix, iy);
NEXT: PRINT
NEXT
' Алгоритм заполнения нулями
x = 1: y = 1: sx = 1
FOR i = 1 TO K
M(x, y) = 0
x = x + sx: y = y + sy
IF x = 1 THEN sx = 0: sy = -1
IF x = n AND sx = 1 THEN sy = 1: sx = 0
IF y = n AND x <> 1 THEN sx = -1: sy = 0
NEXT
'Вывод результата
PRINT STRING$(80, 196)
FOR iy = 1 TO n: FOR ix = 1 TO n
LOCATE , ix * 3: PRINT M(ix, iy);
NEXT: PRINT
NEXT
CLS
RANDOMIZE TIMER
INPUT "vvedite n"; n
INPUT "vvsedite diapozon chisel dlja avto zapolnenija matricy [a,b]"; a, b
IF a > b THEN SWAP a, b
DIM a(n, n)
FOR i = 1 TO n: FOR j = 1 TO n
a(i, j) = INT(RND * ABS(b - a + 1) + a)
NEXT: NEXT
FOR i = 1 TO n
a(1, i) = 0: a(n, i) = 0
a(i, 1) = 0: a(i, n) = 0
NEXT
FOR i = 1 TO n: FOR j = 1 TO n
PRINT USING "####"; a(i, j);
NEXT: PRINT: NEXT
Тестирование выполнено в программе QB64 ( Скачать )