Option Explicit
Private Sub Command1_Click()
Dim d(1 To 10) As Integer
Dim i As Integer
Dim n As Integer
Dim x As Integer
Dim MyMax As Integer
Dim Kmax As Integer
Dim T As Integer
Randomize
n = 0
Do While n < 10
x = Int(Rnd * 90 + 10)
For i = 1 To n
If x = d(n) Then Exit For
Next i
If i > n Then
n = n + 1
d(n) = x
End If
Loop
Me.Cls
'输出数组
For i = 1 To 10
Print d(i),
Next i
Print
'寻找最大值并输出下标
MyMax = d(1)
Kmax = 1
For i = 2 To 10
If d(i) > MyMax Then
MyMax = d(i)
Kmax = i
End If
Next i
Print "最大值:" & MyMax
Print "在第" & Kmax & "元素里。"
Print
'交换元素的值
For i = 1 To 5
T = d(i)
d(i) = d(10 - i + 1)
d(10 - i + 1) = T
Next i
'再次输出数组
For i = 1 To 10
Print d(i),
Next i
End Sub
Private Sub Command1_Click()
Randomize
Dim a(10) As Integer
Print "原来的数组:"
For i = LBound(a) To UBound(a)
a(i) = Int(100 * Rnd()): Print a(i);
Next
Print
abc a()
End Sub
Sub abc(a() As Integer)
Max = LBound(a())
For i = LBound(a) To UBound(a)
If a(i) > a(Max) Then Max = i
Next
Print "Max:"; "a("; Max; ")="; a(Max)
Print: Print "逆置数组后:"
i = LBound(a)
j = UBound(a)
While i < j
t = a(i): a(i) = a(j): a(j) = t
i = i + 1: j = j - 1
Wend
For i = LBound(a) To UBound(a)
Print a(i);
Next
Print
End Sub