VB编写,产生50个随机二位整数,存入数组中,计算总和,将数组元素按升序排序,并按每行10个打印输出

用VB编写程序,产生50个随机二位整数,存入数组中,计算总和,将数组元素按升序排序,并按每行10个打印输出。求代码 急!

被计算机2级考试折磨的可怜娃儿~
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-04-02
Private Sub Form_Load()
Dim mr(1 To 50) As Byte, x As Byte
Dim i As Long, j As Long, t As Long, b As Boolean
Dim so As String
'产生50个随机二位整数
Randomize
For i = 1 To 50
mr(i) = Int((90 * Rnd) + 10) '10~99
t = t + mr(i)
Next
'每行10个输出
so = ""
For i = 1 To 50
so = so & mr(i) & " "
If 0 = (i Mod 10) Then so = so & vbCrLf
Next
Debug.Print so
'输出总和
Debug.Print "Sum:" & t & vbCrLf
'冒泡排序
For i = 1 To 49
b = False
For j = 50 To (i + 1) Step -1
If mr(j - 1) > mr(j) Then
x = mr(j - 1): mr(j - 1) = mr(j): mr(j) = x: b = True
End If
Next
If Not b Then Exit For
Next
'每行10个输出
so = ""
For i = 1 To 50
so = so & mr(i) & " "
If 0 = (i Mod 10) Then so = so & vbCrLf
Next
Debug.Print so
End Sub
相似回答