修改时间:2021-05-25 浏览次数:96 类型:同步测试
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)中存放着升序排列的数据。下列说法正确的是( )
Key=Val(Text1.Text)
i=0:j=9:s=0
Do While i<=j
m=Fix((i+j)/2+0.5)
s=s+1
if Key=a(m) Then
Label1.Caption=Label1.Caption+“→”+Str(m)
Exit Do
End if
if Key<a(m) Then j=m-1 Else i=m+1
Label1.Caption=Label1.Caption+“→”+Str(m)
Loop
Label2.Caption=“经历”+ Str(s)+“步”
Key=Val(Text1.Text)\10
Text2.Text=“”
i=1: j=9: f=False
Do While i<=j And Not f
m=(i+j)\2
if a(m) Mod 10=Key Then
search=m
f=True
Elseif a(m) Mod 10>Key Then
i=m+1
Else
j=m-1
End if
Text2.Text=Text2.Text+Str(m)
Loop
则在执行该程序后,Text2中显示的内容是( )
Private Sub Command1_Click( )
Dim L As Integer, R As Integer,n As Integer
x As Integer
n=Val(Text1.Text)
L=1
R=n+1
Do While
x=(L+R)\2
if 2^X+3*x-5<=n Then L=x+1
Else R=x-1
Loop
Label1.Cption=“方程2^X+3*x-5<=n的最大正整数解为:”+
End Sub
要使程序实现上述算法思想,则方框上的语句是( )
L=1: R=10: n=10: key=78
Do While L<=R
m=Fix((L+R)/2)
If Then
R=m-1
Else
L=m+1
End If
Loop
For i=1 To R
List1.Additem Str(a(i))
Next i
数组元素a(1)到a(10)的值依次为86,78,78,77,73,69,60,54,54,51,若执行该程序段后,列表框List1中输出的数据个数为3,则方框处的代码为( )
a(1)=2:a(2)=2:a(3)=5:a(4)=6:a(5)=7
Key=2
i=1: j=5: flag=False
Do While i<=j And Not Flag
m=(i+j)\2
if Key = a(m) Then
s=“找到第”+Str(m)+“个”
flag=True: Exit Do
Elseif Key<a(m) Then
j=m-1
Else
i=m+1
End if
s=str(m)+s
Loop
Label1.Caption=s
执行该程序后,在标签Label1中显示的内容是( )
Key=Val(Text1.Text)
i=1:j=n*2:flag=False
Do While i+1<=j And Not flag
m=(i+j)\2
If Then m=m-1
If a(m)=Key or a(m+1)=Key Then
Flag=True
Elseif a(m)>key Then
Else
End if
Loop
If a(i)=Key Or a(j)=Key Then flag=True
If flag Then Label1.Caption=“yes” Else Label1.Caption=“no”
划线处的代码正确的是( )
试题篮