试题 试卷
题型:单选题 题类:常考题 难易度:普通
教科版高中信息技术选修一 对分查找变式
i=1:j=1000:flag=True:p=0
key=val(Text1.Text)
Do While i<=j And flag
m=(i+j)\2
p=p+1
if a(m)=key Then flag=False
if a(m)>key Then j=m-1 Then i=m+1
Loop
数组元素a(1)到a(1000)中存放着升序排列的数据。下列说法正确的是( )
Dim a(5) As Integer
Dim i As Integer, j As Integer, t As Integer
a(1) = 52: a(2) = 15: a(3) = 37: a(4) = 22: a(5) = 35
i = 1
Do While i < 5
t = i: j = i + 1
Do While j <= 5
If a(j) > a(t) Then t = j
j = j + 1
x = a(t): a(t) = a(i): a(i) = x
i = i + 1
Text1.Text = Str(a(2))
运行该段代码后,文本框Text1中显示的内容为( )
n = 0 : i = 1 : j = 8
Key = Val(Text1.Text)
Do While i <= j
m = (i + j) \ 2
If Key = d(m) Then Exit Do 'Exit Do表示退出循环
If Key > d(m) Then
j = m - 1 : n = n - 1
Else
i = m + 1 : n = n + 1
End If
Label1.Caption = Str(n)
当输入不同的Key值,运行该程序段后,在标签Label1中显示的不同结果共有( )
i=1: j=5: k=0: s=""
key=Int(Rnd*100)
Do While i <=j
k=k+1
m=(i+j) \ 2
s=s+Str(a(i))
If key=a(m) Then
Exit Do ‘Exit Do表示退出循环
ElseIf key < a(m) Then
j=m-1
i=m+1
Text1.Text=s
数组元素a(1)到a(5)的值依次为“6,18,25,37,49”。若该程序段执行后,k的值为3,则key的值不可能为( )
试题篮