编写程序,随机产生20整数到文本框中,将其中的奇数按从小到大的顺序在一文本框中输出.
Dim a(19) As Integer
Dim i, j As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim mystr As String
mystr = ""
For i = 0 To 19
Randomize()
a(i) = Int(90 * Rnd() + 10)
mystr = mystr & a(i) & Space(2)
If i = 9 Then
mystr = mystr & vbCrLf
End If
Next
TextBox1.Text = mystr
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim s() As Object
Dim k As Integer
Dim mystr As String = ""
Static m As Integer
For i = 0 To 19
If a(i) Mod 2 <> 0 Then
m = m + 1
End If
s(m) = a(i)
Next
For i = 0 To m - 2
For j = i + 1 To m - 1
If s(i) > s(j) Then
k = s(i)
s(i) = s(j)
s(j) = k
End If
Next
Next
For i = 0 To m
mystr = mystr & s(i)
Next
MsgBox(mystr, , "从小到大")
End Sub