怎么用VB编写”随机生成50个两位数,并用第2个单击事件降序排列”,小生在此感谢!
Dim C As Boolean, s%(1 To 50)
Private Sub Form_Click()
Dim i%, j%, t%
Randomize
If C = False Then '第1次生成
Cls
Print "生在的50个数为:"
For i = 1 To 50
s(i) = Int(90 * Rnd + 10)
Print s(i);
If i Mod 5 = 0 Then Print
Next
C = True
Exit Sub
ElseIf C = True Then
For i = 1 To 50
For j = i To 50
If s(j) > s(i) Then
t = s(i)
s(i) = s(j)
s(j) = t
End If
Next
Next
Print "重新排序后为:"
For i = 1 To 50
Print s(i);
If i Mod 5 = 0 Then Print
Next
C = flase
End If
End Sub
温馨提示:内容为网友见解,仅供参考
第1个回答 2007-11-02
Dim a(1 To 50) As Integer
Private Sub Command1_Click()
For n = 1 To 50
a(n) = Int(Rnd * 90 + 10)
Print a(n);
Next
End Sub
Private Sub Command2_Click()
Print
Print "排序后:"
For n = 1 To 50
For m = 2 To 50
If a(n) < a(m) Then my = a(n): a(n) = a(m): a(m) = my
Next
Next
For i = 1 To 50
Print a(i);
Next
End Sub
第2个回答 2007-11-02
Option Base 1
Dim no(50) As Long
Private Sub Command1_Click() '这是第二步
Dim t As Long, j As Integer
For j = 1 To 49
If no(j) < no(j + 1) Then
t = no(j)
no(j) = no(j + 1)
no(j) = t
End If
Next j
For i = 1 To 50
Print no(i);
If i Mod 10 = 0 Then Print
Next i
End Sub
Private Sub Form_Click() '这是第一步
Dim i As Integer
Randomize
For i = 1 To 50
no(i) = CLng(Rnd * 100)
Next i
End Sub
Warning: Invalid argument supplied for foreach() in /www/wwwroot/aolonic.com/skin/templets/default/contents.html on line 45
相似回答