五笔打字通主页
VB程序题:随机产生10个2位数,按从大到小递减的顺序排列,并显示排序结果。VB 源代码 龚沛曾
解题,窗体点击代码如下:
Private Sub Form_Click()
Randomize
Dim tmp As Integer
Dim a(1 To 10) As Integer
Print "排序前为:"
For i = 1 To 10 '开始随机生成10个数
a(i) = Int(Rnd * 89 + 10)
Print a(i);
Next i
Print
' 以下为插入排序
For i = 2 To 10
If a(i) > a(i - 1) Then
tmp = a(i)
For j = i - 1 To 1 Step -1
If tmp < a(j) Then Exit For
a(j + 1) = a(j)
Next j
a(j + 1) = tmp
End If
Next i
Print "排序结果:"
For i = 1 To 10
Print a(i);
Next i
Print
End Sub
Visual Basic程序设计教程(第3版) (龚沛曾等编)课后实验源码
来源:济亨网
本文链接:http://wb86.com/post/82.html