VB程序设计:随机产生10个数,用两种方法排序
2个回答
展开全部
1、选择排序发(从小到滑陆大)局如
Private Sub Command1_Click()
Dim a(10) As Integer
For i = 1 To 10
Randomize
a(i) = Int(Rnd * 90) + 10
Next i
For i = 1 To 9
For j = i + 1 To 10
If a(i) > a(j) Then
r = a(i)
a(i) = a(j)
a(j) = r
End If
Next j
Next i
For i = 1 To 10
Print a(i);
Next i
End Sub
2、冒泡信腊顷排序法
Private Sub Command1_Click()
Dim a(10) As Integer
For i = 1 To 10
Randomize
a(i) = Int(Rnd * 90) + 10
Next i
For i = 1 To 9
For j = 1 To 10 - i
If a(j) > a(j + 1) Then
r = a(j)
a(j) = a(j + 1)
a(j + 1) = r
End If
Next j
Next i
For i = 1 To 10
Print a(i);
Next i
End Sub
Private Sub Command1_Click()
Dim a(10) As Integer
For i = 1 To 10
Randomize
a(i) = Int(Rnd * 90) + 10
Next i
For i = 1 To 9
For j = i + 1 To 10
If a(i) > a(j) Then
r = a(i)
a(i) = a(j)
a(j) = r
End If
Next j
Next i
For i = 1 To 10
Print a(i);
Next i
End Sub
2、冒泡信腊顷排序法
Private Sub Command1_Click()
Dim a(10) As Integer
For i = 1 To 10
Randomize
a(i) = Int(Rnd * 90) + 10
Next i
For i = 1 To 9
For j = 1 To 10 - i
If a(j) > a(j + 1) Then
r = a(j)
a(j) = a(j + 1)
a(j + 1) = r
End If
Next j
Next i
For i = 1 To 10
Print a(i);
Next i
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询