vb编程 产生10个50-100(包括50和100)的随机整数,并用“冒泡排序”按从小到大的顺序输出。
界面效果图也要
额,我要的是vb。net的程序,我没说清楚,我加你好友了
Private Sub Command1_Click()
Dim a(1 To 10) As Integer
Dim i As Integer, j As Integer
Print "随机取到的10个50-100(包括50和100)的随机整数为"
For i = 1 To 10
Randomize
a(i) = Int(Rnd() * 51 + 50)
Print a(i);
Next i
Print
Print "用“冒泡排序”按从小到大的顺序排序后"
For i = 1 To 10
For j = 1 To 10 - i
If a(j) > a(j + 1) Then
t = a(j)
a(j) = a(j + 1)
a(j + 1) = t
End If
Next j
Next i
For i = 1 To 10
Print a(i);
Next i
End Sub
温馨提示:内容为网友见解,仅供参考
第1个回答 2011-05-27
Private Sub Command1_Click()
Dim aR(1 To 10)
Dim i
Dim StartNo, endNO
Me.List1.Clear
Me.List2.Clear
StartNo = Me.StartNo
endNO = Me.endNO
'生成随机数
For i = 1 To 10
Randomize
aR(i) = Int((endNO - StartNo + 1) * Rnd + StartNo) 'Int((100 * Rnd) + 50)
Me.List1.AddItem aR(i)
Next
'冒泡排序
For i = 1 To 10 - 1
For j = i To 10
If aR(i) > aR(j) Then
a = aR(i)
aR(i) = aR(j)
aR(j) = a
End If
Next
Next
For i = 1 To 10
Me.List2.AddItem aR(i)
Next
End Sub
程序上只有5个控件:
列表框2个:Me.List1,Me.List2
文本框2个:Me.StartNo,Me.endNO
一个按钮:Command1
界面就不给你了,应该能明白的!
第2个回答 2011-05-27
邮件已发,278700294@qq.com
Private Sub Command1_Click()
Dim a(9) As Integer, i As Integer, j As Integer
For i = 0 To 9
a(i) = Int(Rnd * 51) + 50
Print a(i);
Next
Print
For i = 0 To 9
For j = 0 To i
If a(i) < a(j) Then t = a(i): a(i) = a(j): a(j) = t
Next
Next
For i = 0 To 9
Print a(i);
Next
Print
End Sub本回答被提问者采纳
Warning: Invalid argument supplied for foreach() in /www/wwwroot/aolonic.com/skin/templets/default/contents.html on line 45
相似回答