如何在数组中查找有无某个数vb编程
展开全部
假设a数组有10个元素。
much = Val(InputBox("请输入一个整数"))
For i = 1 To 9
For j = i + 1 To 10
If a(i) > a(j) Then
temp = a(i)
a(i) = a(j)
a(j) = temp
End If
Next j
Next i
low = 1: Top = 10
f = 0
Do
t = Int((Top + low) / 2)
If much = a(t) Then
f = 1
Else
If much > a(t) Then
low = t + 1
Else
Top = t - 1
End If
End If
Loop While (low < Top) And (f = 0)
If f = 1 Then
Text2.Text = a(t)
Else
Text2.Text = "该数不存在于数组中"
End If
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询