【加试题】小明设计了一个VB程序,随机产生n个1至20之间的整数,并在列表框List1中降序显示:实现上述功能的VB代码如下,加框外代码有误,请改正。
Private Sub Command1_Click()
Dim n, i, j, temp As Integer
Dim a(1 To 10) As Integer
n = Val(Text1.Text)
Randomize
a(1) = Int(Rnd * 20) + 1
For i = 2 To n
a(i) = Int(Rnd * 20) + 1
If a(i) > a(i - 1) Then
temp = a(i)
bot = 1 : Top = n
Do While bot <= Top
‘(1)
If temp < a(m) Then bot = m + 1 Else Top = m - 1
Loop
For k = n To bot + 1 Step -1
‘(2)
Next k
a(bot) = temp
End If
Next i
For j = 1 To n
List1.AddItem Str(a(j))
Next j
End Sub
以上程序段运行时,为了实现上述功能,加框处代码应改正为:
⑴;⑵。