随机产生1-33之间的6个随机数(保证6个数字不重复)按照从大到小的顺序排列
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/27 00:35:15
随机产生1-33之间的6个随机数(保证6个数字不重复)按照从大到小的顺序排列
随机产生1-33之间的6个随机数(保证6个数字不重复)按照从大到小的顺序排列
随机产生1-33之间的6个随机数(保证6个数字不重复)按照从大到小的顺序排列
Private Sub Command1_Click()
Dim num(6) As Integer
Dim i As Integer,j As Integer
Dim tmp As Integer
Randomize '防止每次生出随机数一样
For i = 0 To 5
num(i) = Int(Rnd * 53) + 1
Next
PrintNum "新生成的6个随机数为:",num()
For i = 0 To 5
For j = 0 To 5
If num(j) < num(j + 1) Then
tmp = num(j)
num(j) = num(j + 1)
num(j + 1) = tmp
End If
Next
Next
PrintNum "排序后的6个随机数为:",num()
End Sub
'------------------------------------------------------------------------以下用于打印数组
Public Function PrintNum(str As String,num() As Integer)
Dim tmpString As String
Dim i As Integer
For i = 0 To 5
tmpString = tmpString & " " & num(i)
Next
Print str & tmpString
End Function