修改时间:2024-07-31 浏览次数:217 类型:月考试卷
Key = Val(Text1.Text)
i = 1: j = 100
Do While i <= j
m = (i + j) \ 2
If (1) Then m = m - 1
Sum = (2)
If Key = Sum Then Exit Do ‘Exit Do表示退出循环
If (3) Then
i = m + 2
Else
j = m - 2
End If
Loop
If i > j Then Text2.Text = "没有找到!" Else Text2.Text = Str(m)
实现该功能,则上述程序段3个方框处的表达式分别为( )
Function f(n As Integer) As Long
If n = 1 Then
f =5
Else
f =2 * f(n - 1) - 3
End If
End Function
Private Sub Command1_click()
Dim n As Integer
n = Val(Text1.Text)
Text2.Text = Str(f(n))
End Sub
该程序段运行后,在文本框Text1中输入5,单击命令按钮Command1后,文本框Text2中显示的是( )
i = 1: j = 8: s = ""
key =Text1.Text
Do While i <= j
m =(i + j) \ 2
If key = a(m) Then
s = s + "M"
Exit Do
ElseIf key > a(m) Then
j = m - 1: s = s + "L"
Else
i = m + 1: s = s + "R"
End If
Loop
Text1.Text = s
数组元素a(1)到a(8)的值依次为“4,22,27,32,35,44,56,59”,该程序段执行后,文本框Text1中显示的内容不可能是( )
s = "Inter(R) Core(TM) i3-4130 CPU @ 3.40GHz"
flag = False:k = 0
For i = 1 To Len(s)
ch = Mid(s, i, 1)
If ch >= "A" And ch <= "Z" or ch >= "0" And ch <= "9" Then
If Not flag Then
k = k + 1
flag = True
End If
Else
flag = False
End If
Next i
Text1.Text = Str(k)
Function GCD(m As Long, n As Long) As Long
Dim temp As Long, r As Long
If m < n Then temp = m: m = n: n = temp
d = m - n
Do While d <> n
If d >= n Then
m = d
Else
m = n
n = d
End If
d = m - n
Loop
GCD = n
End Function
Private Sub Command1_Click()
Text1.Text = Str(GCD(48,36))
End Sub
程序运行完后,单击Command1按钮,文本框Text1中显示的是 ( )
Dim a(1 To 5) As Integer, i As Integer
Dim flag As Boolean, j As Integer
a(1) =1 : a(2) = 1 : a(3) = 1 : a(4)= 1 : a(5) = 1
Randomize
For i = 1 To 5
j = 1: flag = True
Do While j <= i - 1 And flag = True
a(i) = Int(Rnd * 5 + 1)
If a(i) = a(j) Then
i = i - 1: flag = False
End If
j = j + 1
Loop
Next i
运行程序后,数组中的数据值可能是( )
Dim a(1 To 10) As Integer
Function Search(L As Integer, R As Integer) As Integer
M = (L + R) \ 2
If a(M) < a(M - 1) And a(M) > a(M + 1) Then
⑴
ElseIf a(M) > a(M - 1) And a(M) > a(M + 1) Then
⑵
ElseIf a(M) > a(M - 1) And a(M) < a(M + 1) Then
⑶
End If
End Function
Private Sub Command1_Click()
Label1.Caption = "“峰顶”值是:" + Str(Search(1, 10))
End Sub
上述程序中划线处可选语句为:
①Search = Search(M + 1 , R)
②Search = Search(L , M - 1)
③Search = a(M)
则(1)(2)(3)处的语句依次是( )
Dim b(1 To 20) As Integer
Private Sub Command1_Click()
Dim i As Integer, j As Integer, m As Integer
i = 1: j = 20
Key = Val(Text1.Text)
Do While (1)
m = (i + j + 1) \ 2
If b(i) < b(m) Then
If (2) Then
j = m - 1
Else
i = m + 1
ElseIf Key = b(m) Then
Exit Do
Else
If Key > b(m) And Key <= b(j) Then
i = m + 1
Else
j = m - 1
End If
Loop
If (3) Then
Label2.Caption = "数组中无此数"
Else
Do While m > 0
If Key = b(m) Then m = m - 1 Else Exit Do
Loop
Label2.Caption = "此数在第" + Str(m + 1) + "个位置"
End If
End Sub
①i > j
②i <= j
③Key < b(m) And Key >= b(i)
④Key> b(m) And Key <=b(j)
则(1)(2)(3)处的语句依次是( )
s = "491053"
For i = 1 To 3
n = Len(s)
k = 1
For j = 2 To n
If Mid(s, k, 1) >= Mid(s, j, 1) Then
k = j
Else
Exit For 'Exit For表示退出循环
End If
Next j
s = Mid(s, 1, k - 1) + Mid(s, k + 1, n - k)
Next i
Label1.Caption = s
执行该程序段后,标签Label1中显示的值是( )
Dim i As Integer, sum As Integer
Dim a(1 To 6) As Integer, b(1 To 6) As Integer
sum = 0
a(6) = 18: a(5) = 7: b(6) = 14: b(5) = 16
For i = 4 To 1 Step -1
a(i) = a(i + 2) - a(i + 1)
b(i) = b(i + 2) - a(i)
If b(i) Mod 3 = 0 Then sum = sum + b(i)
Next i
Text1.Text = Str(sum)
该程序段运行后,文本框Text1中显示的内容是( )
试题篮