主题:菜鸟提问
Private Sub Command1_Click()
Dim s(0 To 9) As Integer, i%, j%, k%, t%
's = Array(71, 45, 34, 64, 75, 37, 98, 54, 51, 88)
Randomize
For i = 0 To 9
s(i) = Int(Rnd(2) * 90) + 10 '产生10个随机数
Next i
Picture1.Print s(0) & Space(2); s(1) & Space(2); s(2) & Space(2); s(3) & Space(2); s(4) & Space(2); s(5) & Space(2); s(6) & Space(2); s(7) & Space(2); s(8) & Space(2); s(9) & Space(2);
' 在picture中输出产生的10个随机数
For j = 0 To 8
For k = 0 To 8 - i
If s(k) > s(k + 1) Then
t = s(k): s(k) = s(k + 1): s(k + 1) = t
End If
Next k
Next j
For m = 0 To 9: Picture2.Print s(m);: Next m
End Sub
这段代码为什么将数组直接初始化时,排序结果能按照我的意愿从小到大输出;而当我用随机数产生的2位数给数组赋值后它的输出结果就和picture中的完全一样没有完成排序功能呢?
Dim s(0 To 9) As Integer, i%, j%, k%, t%
's = Array(71, 45, 34, 64, 75, 37, 98, 54, 51, 88)
Randomize
For i = 0 To 9
s(i) = Int(Rnd(2) * 90) + 10 '产生10个随机数
Next i
Picture1.Print s(0) & Space(2); s(1) & Space(2); s(2) & Space(2); s(3) & Space(2); s(4) & Space(2); s(5) & Space(2); s(6) & Space(2); s(7) & Space(2); s(8) & Space(2); s(9) & Space(2);
' 在picture中输出产生的10个随机数
For j = 0 To 8
For k = 0 To 8 - i
If s(k) > s(k + 1) Then
t = s(k): s(k) = s(k + 1): s(k + 1) = t
End If
Next k
Next j
For m = 0 To 9: Picture2.Print s(m);: Next m
End Sub
这段代码为什么将数组直接初始化时,排序结果能按照我的意愿从小到大输出;而当我用随机数产生的2位数给数组赋值后它的输出结果就和picture中的完全一样没有完成排序功能呢?