题型:单选题 题类:常考题 难易度:普通
浙江省高中信息技术 查找算法及程序实现同步练习
Dim a(1 To 10) As Integer
Private Sub Form_Load()
a(1)=2:a(2)=3:a(3)=3:a(4)=3:a(5)=3
a(6)=6:a(7)=7:a(8)=7:a(9)=8:a(10)=9
End Sub
Private Sub Command1_Click()
Dim key As Integer, i As Integer, j As Integer
Dim m As Integer, p As Integer
key=Val(Text1.Text)
i=1: j=10
Do While i <=j
m=(i+j) \ 2
If a(m)=key Then
p=m
j=m-1
Else If key < a(m) Then
j=m-1
Else
i=m+1
End If
Loop
Text2.Text=Str(p)
End Sub
程序运行时,在文本框Text1中输入3,单击按钮,文本框Text2显示的内容是( )
1 | 5 | 7 | 9 |
4 | 6 | 10 | 15 |
8 | 11 | 12 | 19 |
14 | 16 | 18 | 21 |
已知数据逐行存储在数组a中,在杨氏矩阵数组中查找某数字是否存在的VB程序段如下:
cz = False : i = 1 : j = n
Do While j >= 1 And i <= n
If key < a(s) Then
⑵
ElseIf key > a(s) Then
⑶
Else
cz = True:Exit Do
End If
Loop
方框中的代码由以下三部分组成:
①j = j - 1
②s = (i - 1) * n + j
③i = i + 1
代码顺序正确的选项是( )
试题篮