展开全部
Dim a(20) As Integer
Private Sub Command1_Click()
Dim k, low, high, midd As Integer
low = 0
high = 20
k = Val(Text1.Text)
Do While low <= high
midd = (low + high) / 2
If k = a(midd) Then
Print midd '如果找到就打印出该数在数组中的位置
Exit Sub
ElseIf k < a(midd) Then
high = midd - 1
Else
low = midd + 1
End If
Loop
Print "没找到这个数"
End Sub
Private Sub Form_Load()
dim i as integer
For i = 0 To 20
a(i) = i
Next i
End Sub
Private Sub Command1_Click()
Dim k, low, high, midd As Integer
low = 0
high = 20
k = Val(Text1.Text)
Do While low <= high
midd = (low + high) / 2
If k = a(midd) Then
Print midd '如果找到就打印出该数在数组中的位置
Exit Sub
ElseIf k < a(midd) Then
high = midd - 1
Else
low = midd + 1
End If
Loop
Print "没找到这个数"
End Sub
Private Sub Form_Load()
dim i as integer
For i = 0 To 20
a(i) = i
Next i
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询