题型:单选题 题类:常考题 难易度:普通
《冒泡排序》同步练习
s = ""
For i = 1 To 3
For j = 7 To i + 1 Step -1
If a(j) < a(j - 1) Then
t = a(j): a(j) = a(j - 1): a(j - 1) = t
End If
Next j
s = s + Str(a(i))
Next i
Text1.Text = s
数组元素a(1)到a(7)的数据依次为“3,9,1,5,8,6,2”,经过该程序段“加工”后,文本框Text1中显示的内容是( )
例如,有如下年龄存在数组a中:
a(1) | a(2) | a(3) | a(4) | a(5) | a(6) | a(7) | a(8) | a(9) | a(10) |
20 | 19 | 18 | 19 | 15 | 12 | 15 | 20 | 17 | 19 |
利用一个数组b(b(10 To 20))记录每个数出现的次数:
b(10) | b(11) | b(12) | b(13) | b(14) | b(15) | b(16) | b(17) | b(18) | b(19) | b(20) |
0 | 0 | 1 | 0 | 0 | 2 | 0 | 1 | 1 | 3 | 2 |
根据数组b对数组a进行排序:
a(1) | a(2) | a(3) | a(4) | a(5) | a(6) | a(7) | a(8) | a(9) | a(10) |
12 | 15 | 15 | 17 | 18 | 19 | 19 | 19 | 20 | 20 |
Dim a(10000) As Integer ‘存放读入的年龄数据
Dim b(100) As Integer ‘存放各个年龄出现的个数
Private Sub Command1_Click()
‘从数据库读入年龄数据放入数组a中
End Sub
Private Sub Command2_Click()
For i = 1 To 100
b(i) = 0
Next i
For i = 1 To 10000 ‘统计每个年龄数据的个数
①
Next i
End Sub
Private Sub Command3_Click()
j = 0
For i = 1 To 100
If b(i) <> 0 Then
Do While b(i) <> 0
②
a(j) = i
‘③
Loop
End If
Next i
For i = 1 To 10000
List2.AddItem Str(a(i))
Next i
End Sub
试题篮