1Answers
Solve: VB code source program: randomly generate 10 two-digit, single number. Sort from small to large, double, from big to small
Asked by: Joyce 239 views IT
Solve: VB code source program: randomly generate 10 two-digit, single number. Sort from small to large, double, from big to small
+6Votes
完整的程序参考
Private Sub sort(ByRef b() As Long, ByVal n)
n = n – 1
For i = 0 To n
For j = 0 To n – i – 1
If b(j) > b(j + 1) Then
t = b(j)
b(j) = b(j + 1)
b(j + 1) = t
End If
Next j
Next
End Sub
Private Sub Command1_Click()
Dim a(10) As Long, b(10) As Long
Dim c, i, i1, i2 As Long
i1 = 0
i2 = 0
For i = 0 To 9
c = Int(Rnd * 100) + 1
If c Mod 2 = 0 Then
a(i1) = c
i1 = i1 + 1
Else
b(i2) = c
i2 = i2 + 1
End If
Next
Call sort(b, i2)
For i = 0 To i2 – 1
Print b(i),
Next
Print
Call sort(a, i1)
For i = i1 – 1 To 0 Step -1
Print a(i),
Next
Print
End Sub