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