修改时间:2024-07-31 浏览次数:125 类型:月考试卷
n=0:i=1:j=8
Key=Val(Text 1.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
Loop
Label 1.Caption=Str(n)
当输入不同的Key值, 运行该程序段后, 在标签Label1中显示的不同结果共有( )
key=Val(Text 1.Text)
Text 2.Text=“”
flag=True
i=1:j=8
Do While i<=j And flag=True
m=(i+j)\2
If key=a(m) Then
flag=False
ElseIf key>a(m) Then
i=m+1
Else
j=m-1
End If
Text 2.Text=Text 2.Text+Str(m)
Loop
数组元素a(1)到a(8)的值依次为“1,3,5,8,10,13,16,21”,在文本框Text 1中输入7,执行该程序段,下列说法正确的是( )
Dim flag As Boolean
i=1: flag=True
Do While i<= 5 And flag=True
flag=False
For j=6 To i+1 Step -1
If a(j) <a(j-1) Then
k=a(i):a(i)=a(j-1):a(j-1)=k
flag=True
End If
Next j
i=i+1
Loop
下列数据序列中,在加工过程中划线处语句执行次数最多的是( )
Const n= 10
Dima(1 To n) As Integer ‘定义数组a
Private SubForm_Load()
Randomize
For i=1 To n '产生n个随机自然数,并依次存放在数组a中
List 1.Add ItemS tr(a(i))
Next i
End Sub
Function Find Min(x As Integer) '寻找当前需要交换的数组元素下标
Dim k As Integer, j As Integer
k=x
For j=x+1Ton
Next j
Find Min=k
End Function
Private Sub Command 1_Click()
Dim i As Integer, k As Integer, t As Integer
For i= 1 To 9
If k<>i Then
t=a(i):a(i)=a(k):a(k)=t
End If
Next i
For i=1 To n
List 2.Add Item Str(a(i))
Next i
End Sub
试题篮