21 апреля 2020
' Написать программу, которая принимает число n и выводит таблицу размером n * n, заполненную числами от 1 до n^2 по спирали, ' выходящей из левого верхнего угла и закрученной по часовой стрелке.
Dim intN, intX, intY, intCurN, intCor, intCorPos As Integer
Console.Write("Введите число от 1 до 9: ")
intN = CInt(Console.ReadLine)
For i As Integer = 1 To intN
Console.Write("{0,3}", i)
Next
intCurN = intN + 1
intY = 1 : intX = -3 : intCor = 2
For j As Integer = 0 To intN - 1
For i As Integer = 0 To intN - intCor
If intCurN > 9 Then intCorPos = -1
Console.SetCursorPosition(Console.CursorLeft - 1 + intCorPos, Console.CursorTop + intY)
Console.Write(intCurN)
intCurN += 1
Next
For i As Integer = 0 To intN - intCor
If intCurN > 9 Then intCorPos = -1
Console.SetCursorPosition(Console.CursorLeft - 1 + intX + intCorPos, Console.CursorTop)
Console.Write(intCurN)
intCurN += 1
Next
intY = -intY : intX = -intX : intCor += 1
Next
Console.ReadKey()
Ответить
Пожаловаться