vb编程,用随机函数产生50个10~100之间的互不相同的整数存于一数组中,并以升序每行10个数显示在窗体上

如题所述

Private Sub Command1_Click()
Dim x(90) As Integer

'高效代码,产生无重复随机数
For i = 10 To 100
x(i - 10) = i
Next
Randomize
For i = 1 To 50
j = Int(Rnd * (91 - i)) + i
t = x(i)
x(i) = x(j)
x(j) = t
Next

'排序
For i = 1 To 50
For j = 1 To i
If x(i) < x(j) Then t = x(i): x(i) = x(j): x(j) = t
Next
Next

'显示
For i = 1 To 50
Print x(i);
If i Mod 10 = 0 Then Print
Next
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-05-23
Private Sub Command1_Click()
Dim NumA(50) As Integer, Tmp1 As Long, Tmp2 As Long
For Tmp1 = 1 To 50
NumA(Tmp1) = Rnd() * 90 + 10
Next
NumA(0) = NumA(1)
For Tmp1 = 1 To 49
For Tmp2 = Tmp1 To 50
If NumA(Tmp2) < NumA(Tmp1) Then
NumA(0) = NumA(Tmp2)
NumA(Tmp2) = NumA(Tmp1)
NumA(Tmp1) = NumA(0)
End If
Next
If Tmp1 Mod 10 = 0 Then
Print NumA(Tmp1)
Else
Print NumA(Tmp1);
End If
Next
Print NumA(50)
End Sub本回答被提问者采纳
相似回答