题型:单选题 题类:常考题 难易度:普通
浙江省91高中联盟2018-2019学年高二下学期信息技术期中考试试卷
a(1) |
a(2) |
a(3) |
…… |
a(n —2) |
a(n—1) |
a(n) |
3 |
25 |
38 |
…… |
55 |
31 |
12 |
依据对分查找思想,设计一个在数组a中查找数据key的程序。实现该功能的VB程序如下,但加框处代码有错,请改正。
Private Sub Command1_Click()
Const n = 6
Dim a(1 To n)As Integer,flag As Boolean
Dim i As Integer,j As Integer,m As Integer,key As Integer
'读取一组正整数,按上述规则存入数组a中,代码略。
key = VaKText1. Text)
i = 1
j = (n + 1) \ 2
flag = False
Do While And Not flag ‘①
m = (i + j) \ 2
If key = a(m) Then
flag = True
ElseIf key< a(m) Then
j = m - 1
Else
i = m + 1
End If
Loop
If Not flag And j > 0 Then
m = ‘②
If key = a(m) Then flag = True
End If
If flag Then
Text2. Text = Str(m)
Else
Text2. Text = "找不到"
End If
End Sub
①{#blank#}1{#/blank#} ②{#blank#}2{#/blank#}
试题篮