Advertisement
Guest User

8.23 actual

a guest
May 30th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. Sub sagasg()
  2.  
  3. Dim n As Integer, m As Integer, a() As Integer, i As Integer, j As Integer, min As Integer, max As Integer, min_ As Integer, max_ As Integer
  4.  
  5. n = InputBox("Enter N, my sweety")
  6. m = InputBox("Enter M, my sweet prince")
  7.  
  8. ReDim a(n, m)
  9.  
  10. For i = 1 To n
  11. For j = 1 To m
  12. a(i, j) = InputBox("Enter A[" & i & " , " & j & "], my dear friend")
  13. Next j
  14. Next i
  15.  
  16. MsgBox (Replace(a, n, m))
  17.  
  18. End Sub
  19.  
  20. Function Replace(a() As Integer, n As Integer, m As Integer)
  21.  
  22. Dim i As Integer, j As Integer, min As Integer, max As Integer, min_ As Integer, max_ As Integer
  23.  
  24. max_ = 1
  25. min_ = 1
  26. max = a(1, 1)
  27. min = a(1, 1)
  28.  
  29. For i = 1 To n
  30. For j = 1 To m
  31.  
  32. If (a(i, j) < min) Then
  33. min = a(i, j)
  34. min_ = i
  35. End If
  36.  
  37. If (a(i, j) > max) Then
  38. max = a(i, j)
  39. max_ = i
  40. End If
  41.  
  42. Next j
  43. Next i
  44.  
  45. Dim buffer() As Integer
  46. ReDim buffer(m)
  47.  
  48. For i = 1 To m
  49. buffer(i) = a(max_, i)
  50. Next i
  51.  
  52. For i = 1 To m
  53. a(max_, i) = a(min, i)
  54. Next i
  55.  
  56. For i = 1 To m
  57. a(min_, i) = buffer(i)
  58. Next i
  59.  
  60. Dim ans As String
  61.  
  62. For i = 1 To n
  63. For j = 1 To m
  64. ans = ans & " " & a(i, j)
  65. Next j
  66. ans = ans & Chr(13)
  67. Next i
  68.  
  69. Replace = ans
  70. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement