Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Base 1
- Sub spiral()
- Const rows As Integer = 4
- Const cols As Integer = 5
- Dim matrix(rows, cols) As Integer
- For i = 1 To rows
- For j = 1 To cols
- matrix(i, j) = InputBox("Vvedite element (" & i & ", " & j & ")")
- Next j
- Next i
- Dim top, bottom, left, right, index, direction As Integer
- top = 1
- bottom = rows
- left = 1
- right = cols
- index = 1
- direction = 0
- Do While (top <= bottom) And (left <= right)
- Select Case (direction Mod 4)
- Case 0
- For col = left To right
- matrix(top, col) = index
- index = index + 1
- Next col
- top = top + 1
- direction = direction + 1
- Case 1
- For Row = top To bottom
- matrix(Row, right) = index
- index = index + 1
- Next Row
- right = right - 1
- direction = direction + 1
- Case 2
- For col = right To left Step -1
- matrix(bottom, col) = index
- index = index + 1
- Next col
- bottom = bottom - 1
- direction = direction + 1
- Case 3
- For Row = bottom To top Step -1
- matrix(Row, left) = index
- index = index + 1
- Next Row
- left = left + 1
- direction = direction + 1
- End Select
- Loop
- s = ""
- For i = 1 To rows
- For j = 1 To cols
- s = s & matrix(i, j) & Chr(9)
- Next j
- s = s & Chr(10)
- Next i
- MsgBox (s)
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement