Private Sub Command1_Click()
Dim a(1 to 10) ,i ,j,s as integer
Randomize
For i=1 to 10 //随机10个产生1-100的整数
a(i) = Int(Rnd * 100) + 1
next i
for i=1 to 9
for j=i+1 to 10
if a(i)>a(j) then //如果前面的比后面大,那么就让他们交换
s=a(i)
a(i)=a(j)
a(j)=s
end if
next j
next i
for i=1 to 10
Print a(i)
next i
end Sub
有什么不明白的,可以追问。
Dim n(9) As Integer
For i = 0 To 9
Randomize '初始化
n(i) = Rnd * 100 '赋随机值
Next i
Dim temp As Integer '用作改变位置临时存储
For i = 0 To 8
If n(i) > n(i + 1) Then '判断是否前一位大于后一位
temp = n(i)
n(i) = n(i + 1)
n(i + 1) = temp
i = -1 '为了更准确,让它重新开始
End If
Next i
For i = 0 To 9
Print "第" & i + 1 & "位:" & n(i) '输出
Next i