level 3
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) '时间暂停
Private Sub Form_Load()
Randomize '随机数模块
Dim a(10) As Integer '数组
Text1 = " " '需要添加一个text模块
For i = 1 To 10 '随机输入
a(i) = Int((1 - 100 + 1) * Rnd + 100)
Text1 = Text1 & " " & a(i)
Next
Dim j, c 'j为交换数,c为跳出条件
Do
For i = 1 To 9
Sleep 100
If a(i) < a(i + 1) Then '交换
j = a(i)
a(i) = a(i + 1)
a(i + 1) = j
Else
c = c + 1 '顺序对就将c加1
End If
Text1 = " "
For n = 1 To 10 '每次交换完都输出一次
Text1 = Text1 & " " & a(n)
Nex
Next
If c = 9 Then '如果满足条件就跳出
Exit Do
End If
c = 0 '不满足就清零
Loop
End Sub
2022年09月04日 05点09分
5