vb编程 产生10个50-100(包括50和100)的随机整数,并用“冒泡排序”按从小到大的顺序输出。
3个回答
展开全部
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 "用“冒泡排序”按从小到大的顺序排序后"
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
展开全部
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
界面就不给你了,应该能明白的!
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
界面就不给你了,应该能明白的!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
邮件已发,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
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
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
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询