修改时间:2024-07-31 浏览次数:282 类型:期中考试
n=0
i=1
j=6
key=val(Text1 text)
f=False
Do While i<=j And Not f
m=(i+j+1)\2
n=n+1
If key=d(m) Then
f=True
ElseIf key>d(m) Then
j=m-1
Else
i=m+1
End if
Loop
数组元素d(1)到d(6)的值依次为“87,72,53,41,29,18”,若该程段运行结束后,n的值为2,则key的值是 ( )
图a
图b
Private Sub Command1_Click()
Dim s As String, c1 As String, c2 As Integer
Dim n As Integer, i As Integer
Dim f As Boolean
s = Text1.Text
n = Len(s)
f = True
For i = 1 To n \ 2
c1 = ①
c2 = Mid(s, n - i + 1, 1)
If c1 <> c2 Then
f = False
Exit For
End If
Next i
If ② Then
Label2.Caption = "对称"
Else
Label2.Caption = "不对称"
End If
End Sub
图a
图b
图c
图d
实现上述功能的VB程序如下,代码加框处有错,请改正。
Dim a(1 to 10) As Integer ‘存储原始数据
Dim b(1 to 10)As Integer ‘存放名次
Private Sub Command1_Click()
Dim i As Integer, j As Integer, n As Integer
For i=1 To 10
n=0
For j=1 To 10
If
Then n=n+1 ‘①
‘②
Next j
Next i
For i= 1 to 10
List2.Additem a(i)&” ”&b(i)
Next i
End Sub
Private Sub Form_Load()
‘随机产生10个[60,100]之间的随机数,并显示在List1中,代码略。
End Sub
①处代码应改为:
②处代码应改为:
以下程序实现了冒泡排序的优化,请在划线处填写合适的代码。
Dim n As Integer
Dim a (1 to 100) As Integer
Private Sub Form_Load()
‘n=10,排序前生成的数据存储在数组a中,并在列表框List1中显示
‘代码略
End Sub
Private Sub Command1_Click()
Dim i As Integer, j As Integer, start As Integer, t As Integer
Do While i < n
start = n
For j = n To i Step
If a(j) < a(j - 1) Then
t = a(j): : a(j - 1) = t
start = j
End If
Next j
Loop
For i = 1 To n
List2.AddItem Str(a(i))
Next i
End Sub
试题篮