Private Sub Form_Click()
Const N = 10
Dim A(N), I, j, num, top, bot, min, loca As Integer
Dim C, mynum As String
A(0) = 11: A(1) = 12: A(2) = 13: A(3) = 43: A(4) = 55: A(5) = 62
A(6) = 71: A(7) = 80: A(8) = 121: A(9) = 224
For I = 0 To N - 1
Print A(I);
Next
Print
mynum = InputBox("input the find number!", "find")
num = mynum
loca = -1
top = 0: bot = N - 1
If num < A(0) Or num > A(N - 1) Then loca = -2
Do While loca = -1 And top <= bot
min = Int((bot + top) / 2)
If num = A(min) Then
loca = min
Print num & "的位置在第" & loca + 1 & "个"
ElseIf num < A(min) Then
bot = min - 1
Else
top = min + 1
End If
Loop
If loca = -2 Or loca = -1 Then Print "数组中无" & num
End Sub
[此贴子已经被作者于2007-3-28 19:16:24编辑过]