你的这个作业我能帮你写,不过你还是要自己看一遍
要不考试的时候就蒙了^_^
有什么不懂的直接Hi上P我就好,我代码里就不做解释了
界面上只需要3个Label
Label1
Label2
Label3
自动回行设为true
每行长度允许范围为40 (= 数字(3字符) + 空格(1字符))
通常情况下 宋体, 9pt 的话 设长255 宽90
以下是代码,直接套Form_load事件就可以了
Dim i, j, m, n, lowB, highB, tmpNum As Integer
Dim myArray(0 To 59) As Integer
Dim evenStr As String
Dim evenArray() As Integer
Dim oddStr As String
Dim oddArray() As Integer
Dim notRe As Boolean
i = 0
j = 0
m = 0
n = 0
lowB = 100
highB = 200
tmpNum = 0
notRe = False
evenStr = ""
oddStr = ""
Label1.Text = "随机数据: " & Chr(13) & Chr(10)
Label2.Text = "奇数排序: " & Chr(13) & Chr(10)
Label3.Text = "偶数排序: " & Chr(13) & Chr(10)
Randomize()
For i = 0 To 60 - 1
notRe = False
Do While (notRe = False)
notRe = True
myArray(i) = Int((highB - lowB + 1) * Rnd() + lowB)
If Not i = 0 Then
For j = 0 To i - 1
If myArray(i) = myArray(j) Then notRe = False
Next
End If
Loop
Label1.Text = Label1.Text & myArray(i) & " "
If myArray(i) Mod 2 = 0 Then
evenStr = evenStr & myArray(i) & " "
Else
oddStr = oddStr & myArray(i) & " "
End If
Next
m = Split(Trim(evenStr), " ").Length
n = Split(Trim(oddStr), " ").Length
ReDim evenArray(m)
ReDim oddArray(n)
For i = 0 To m - 1
evenArray(i) = CInt(Split(Trim(evenStr), " ")(i))
Next
For i = 0 To n - 1
oddArray(i) = Split(Trim(oddStr), " ")(i)
Next
For i = 0 To m - 1
For j = 0 To m - 2
If evenArray(j) > evenArray(j + 1) Then
tmpNum = evenArray(j + 1)
evenArray(j + 1) = evenArray(j)
evenArray(j) = tmpNum
End If
Next
Next
For i = 0 To n - 1
For j = 0 To n - 2
If oddArray(j) < oddArray(j + 1) Then
tmpNum = oddArray(j + 1)
oddArray(j + 1) = oddArray(j)
oddArray(j) = tmpNum
End If
Next
Next
For i = 0 To m - 1
Label3.Text = Label3.Text & evenArray(i) & " "
Next
For i = 0 To n - 1
Label2.Text = Label2.Text & oddArray(i) & " "
Next
输出测试结果
程序代码简单,界面的自己搞吧,VB这东西不自己动手是不行的。
1定义60个整数,设定范围。
2定义偶数 ,比较 (循环),然后排列,输出①。
3定义奇数,比较(循环),然后排列,输出②。