Advertisement
Guest User

Untitled

a guest
Feb 18th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Base 1
  2. Sub spiral()
  3.  
  4.  
  5.     Dim rows As Integer
  6.     Dim cols As Integer
  7.    
  8.     rows = InputBox("Chislo strok")
  9.     cols = InputBox("Chislo stolbtsev")
  10.      
  11.     Dim matrix() As Integer
  12.     ReDim matrix(rows, cols)
  13.    
  14.     For i = 1 To rows
  15.         For j = 1 To cols
  16.             matrix(i, j) = InputBox("Vvedite element (" & i & ", " & j & ")")
  17.             Next j
  18.         Next i
  19.        
  20.    
  21.     s = ""
  22.     For i = 1 To rows
  23.         For j = 1 To cols
  24.             s = s & matrix(i, j) & Chr(9)
  25.         Next j
  26.         s = s & Chr(10)
  27.     Next i
  28.     MsgBox (s)
  29.        
  30.    
  31.     Dim top, bottom, left, right, index, direction As Integer
  32.     top = 1
  33.     bottom = rows
  34.     left = 1
  35.     right = cols
  36.     direction = 0
  37.    
  38.     s = ""
  39.    
  40.     Do While (top <= bottom) And (left <= right)
  41.         Select Case (direction Mod 4)
  42.             Case 0
  43.                 For col = left To right
  44.                     s = s & " " & matrix(top, col)
  45.                 Next col
  46.                 top = top + 1
  47.                 direction = direction + 1
  48.             Case 1
  49.                 For Row = top To bottom
  50.                     s = s & " " & matrix(Row, right)
  51.                 Next Row
  52.                 right = right - 1
  53.                 direction = direction + 1
  54.             Case 2
  55.                 For col = right To left Step -1
  56.                     s = s & " " & matrix(bottom, col)
  57.                 Next col
  58.                 bottom = bottom - 1
  59.                 direction = direction + 1
  60.             Case 3
  61.                 For Row = bottom To top Step -1
  62.                     s = s & " " & matrix(Row, left)
  63.                 Next Row
  64.                 left = left + 1
  65.                 direction = direction + 1
  66.         End Select
  67.     Loop
  68.    
  69.     MsgBox (s)
  70.  
  71. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement