冒泡排序VB代码输入五个数,并降序排列Private Sub Command1_Click()Dim a As DoubleDim b(1 To 5) As DoubleDim c As Doublea = 1Do While a 1a = c + 1Do While a >= 2If b(a) > b(a - 1) Thenb(a) = b(a) + b(a - 1)b(a - 1) = b(a) - b(a - 1)b(a) =
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/06 04:10:24
冒泡排序VB代码输入五个数,并降序排列Private Sub Command1_Click()Dim a As DoubleDim b(1 To 5) As DoubleDim c As Doublea = 1Do While a 1a = c + 1Do While a >= 2If b(a) > b(a - 1) Thenb(a) = b(a) + b(a - 1)b(a - 1) = b(a) - b(a - 1)b(a) =
冒泡排序VB代码
输入五个数,并降序排列
Private Sub Command1_Click()
Dim a As Double
Dim b(1 To 5) As Double
Dim c As Double
a = 1
Do While a 1
a = c + 1
Do While a >= 2
If b(a) > b(a - 1) Then
b(a) = b(a) + b(a - 1)
b(a - 1) = b(a) - b(a - 1)
b(a) = b(a) - b(a - 1)
End If
a = a - 1
Loop
c = c - 1
Loop
Print b(1),b(2),b(3),b(4),b(5)
End Sub
哪里错了?
改为这样后哪里错了?
Private Sub Command1_Click()
Dim a As Double
Dim b(1 To 5) As Double
Dim c As Double
a = 1
Do While a 1
a = 1
Do While a
冒泡排序VB代码输入五个数,并降序排列Private Sub Command1_Click()Dim a As DoubleDim b(1 To 5) As DoubleDim c As Doublea = 1Do While a 1a = c + 1Do While a >= 2If b(a) > b(a - 1) Thenb(a) = b(a) + b(a - 1)b(a - 1) = b(a) - b(a - 1)b(a) =
Private Sub Command1_Click()
Dim i As integer, j as integer
Dim b(1 To 5) As Double
Dim tmp As Double
for i=1 to 5
b(i) = InputBox("")
next
for i=1 to 4
for j=i+1 to 5
If b(i) < b(j) Then
tmp= b(i)
b(i) = b(j)
b(j) = tmp
End If
next
next
Print b(1), b(2), b(3), b(4), b(5)
End Sub
这样简洁多啦 一目了然