修改时间:2024-07-31 浏览次数:102 类型:月考试卷
i = 1: flag = True
Do While i < = 4 And flag = True
flag=False
For j = 6 To i + 1 Step -1
If a(j) > a(j - 1) Then
t = a(j): a(j)=a(j-1): a(j-1) = t
flag = True
End If
Next j
i = i + 1
Loop
数组元素a(1)到a(6)的值依次为48,36,24,97,77,23,经过该程序段加工后,变量i的值是( )
i = 1: s = ""
Do While i <= 3
k = i : j = i + 1
Do While j <= 8
If a(j) < a(k) Then k = j
j = j + 1
Loop
If i <> k Then
t = a(i): a(i) = a(k): a(k) = t
n = n + 1
End If
s = s + Str(a(i)) : i = i + 1
Loop
Label1.Caption = Str(n) + ":" + s
数组a(1)到a(8)依次为:16,19,8,20,4,12,6,15,程序运行后,标签中显示的值为( )
s=“7218634594” : n=Len(s): c=0
For i=1 To n-1
a(i)=Val(Mid(s, i, 2))
Next i
For i=1 To n-2 Step 2
k=i
For j=i+2 To n-1 Step 2
If a(j) < a(k) Then k=j
Next j
If k <> i Then
t=a(i): a(i)=a(k): a(k)=t: c=c+1
End If
Next i
Text1.Text=Str(c)
该程序段运行后,Text1中显示的内容是( )
i = 1: j = 7: s = ""
key = Int(Rnd * 100)
Do While i <= j
m = (i + j) \ 2
If key = a(m) Then
s = s + "M": Exit Do '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(9)的值依次为“24,35,38,41,45,69,78”。若该程序段执行后,文本框Text1中显示的内容可能是( )
Dim conn As New ADODB. Connection
Dim rs As New ADODB. Recordset
Dim n as Integer
Private Sub Form_ Load()
conn. ConnectionString ="Provider= Microsoft.Ace.
OLEDB.12.0; data source ="+App. Path+"\data\data. accdb"
conn. Open
sql="select*from student"
Set rs. ActiveConnection=conn
rs. Open sql
n=0
Do while Not rs. EOF
List1.AddItem rs("name")
n=n+1
rs. MoveNext
Loop
End Sub
运行上述程序,以下说法不正确的是( )
实现上述功能的VB程序如下:
Dim a(1 To 8) As Integer
Dim n As Integer
Private Sub Form_Load()
'排序前的8个数据存储在数组a中,并在列表框List1中显示
'代码略
End Sub
Private Sub Command1_Click()
Dim i As Integer, j As Integer, k As Integer
Dim pos As Integer '变量pos存储指定数据的位置(即下标值)
Dim s As String '变量s存储pos变化情况
s = Text1.Text
pos = Val(Text1.Text)
For i = 1 To n - 1
For j = n To i + 1 Step -1
If a(j) < a(j - 1) Then
k = a(j - 1)
a(j)=a(j-1) '(2)改错
a(j) = k
'如果pos位置的数据参与交换,则更新pos值,记录pos变化情况
If pos = j Then
pos = j - 1
s = s + "→" + Str(pos)
ElseIf Then '填写代码
pos = j
s = s + "→" + Str(pos)
End If
End If
Next j
Next i
Label4.Caption = "位置变化情况:" + s
For i = 1 To n
List2.AddItem Str(a(i))
Next i
End Sub
实现上述功能的VB程序如下,在橫线处填入合适的代码。
Const n = 10
Dim a(1 To n) As Integer
Private Sub Command1_Click()
Dim i As Integer, j As Integer, t As Integer
Dim k As Integer, bottom As Integer
'获取排序前数据,依次存储在数组 a 中,并在文本框 Text1 中显示。代码略
bottom = n: i = 1
Do While i <= bottom - 1
k = i: j = bottom
Do While j > i
If a(j) < a(k) Then
k = j
ElseIf a(j) = a(i) Then '若发现重复数据,进行剔除处理
a(j) = a(bottom)
IfThen k = j
bottom = bottom - 1
End If
j = j - 1
Loop
If k <> i Then
t = a(k): a(k) = a(i): a(i) = t
Else
EndIF
Loop
For i = 1 To
Text2.Text = Text2.Text + Str(a(i))
Next i
End Sub
试题篮