VB的问题 数组排列
利用随机函数Rnd产生10个随机三位数(100~999),单击窗体后,在窗体的第一行显示这10个数,在第二行显示排序后的这10个数(从大到小)。排序功能要求写成一个独立的...
利用随机函数Rnd产生10个随机三位数(100~999),单击窗体后,在窗体的第一行显示这10个数,在第二行显示排序后的这10个数(从大到小)。排序功能要求写成一个独立的过程。提示: Sub Sort(x() As Integer)
展开
1个回答
展开全部
Private Sub Form_Click()
Dim a(1 To 10) As Integer
Dim n As Integer
For n = 1 To 10
a(n) = Int(Rnd * 899 + 100)
Print a(n);
Next
Print
Call sort(a)
Print
End Sub
Public Sub sort(ByRef n() As Integer)
Dim i As Integer
Dim j As Integer
Dim t As Integer
c = UBound(n)
For i = LBound(n) To c
For j = i + 1 To c
If n(j) > n(i) Then
t = n(i)
n(i) = n(j)
n(j) = t
End If
Next j
Next i
For i = LBound(n) To c
Print n(i);
Next i
End Sub
Dim a(1 To 10) As Integer
Dim n As Integer
For n = 1 To 10
a(n) = Int(Rnd * 899 + 100)
Print a(n);
Next
Call sort(a)
End Sub
Public Sub sort(ByRef n() As Integer)
Dim i As Integer
Dim j As Integer
Dim t As Integer
c = UBound(n)
For i = LBound(n) To c
For j = i + 1 To c
If n(j) > n(i) Then
t = n(i)
n(i) = n(j)
n(j) = t
End If
Next j
Next i
For i = LBound(n) To c
Print n(i);
Next i
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询