vb问题利用随机函数产生80个10~99之间的随机整数,

问题描述:

vb问题利用随机函数产生80个10~99之间的随机整数,
利用随机函数产生80个10~99之间的随机整数,将其中的偶数按由小到大的顺序排列并输出,将奇数按由大到小的顺序排列并输出在两个文本框中每行十个 运用基本语句 dmwk2@163.com

我已经上机验证过了,正确.
思路:
产生80个随机数,把这80个随机数由小到大排序,然后从第1个到第80个的顺序挑选偶数,赋值给字符串s1,够10个换行 .
再从第80个到第1个的顺序挑选奇数,赋值给字符串s2,同上.
有一点很重要:把这两个文本框的mutltiLine属性要改为 True
Private Sub Command1_Click()
Dim s1, s2 As String
Randomize
Dim a(80) As Integer
For i = 1 To 80
a(i) = 10 + Int(Rnd * 90)
Next i
For i = 1 To 79
For j = i + 1 To 80
If a(i) > a(j) Then t = a(i): a(i) = a(j): a(j) = t
Next j
Next i
n = 0
For i = 1 To 80
If a(i) Mod 2 = 0 Then
s1 = s1 + Str(a(i))
n = n + 1
If n Mod 10 = 0 Then s1 = s1 + Chr$(13) + Chr$(10)
End If
Next i
Text1.Text = s1
n = 0
For i = 80 To 1 Step -1
If a(i) Mod 20 Then
s2 = s2 + Str(a(i))
n = n + 1
If n Mod 10 = 0 Then s2 = s2 + Chr$(13) + Chr$(10)
End If
Next i
Text2.Text = s2
End Sub