vb编程:定义一个数组A(10),对数组中的元素排降序。要求排序算法用子程序过程实现。
1个回答
2009-03-18
展开全部
Private Sub Command1_Click()
Dim a(10) As Integer, i As Integer
Print "随机生成数组:"
For i = 1 To 10
a(i) = Int(Rnd * 100) + 1
Print a(i);
Next i
Print
Print "降序排序后为:"
Call px(a)
End Sub
Sub px(a() As Integer)
For j = 1 To 9
For i = 1 To 9
If a(i) < a(i + 1) Then temp = a(i + 1): a(i + 1) = a(i): a(i) = temp
Next i
Next j
For i = 1 To 10
Print a(i);
Next i
End Sub
Dim a(10) As Integer, i As Integer
Print "随机生成数组:"
For i = 1 To 10
a(i) = Int(Rnd * 100) + 1
Print a(i);
Next i
Print "降序排序后为:"
Call px(a)
End Sub
Sub px(a() As Integer)
For j = 1 To 9
For i = 1 To 9
If a(i) < a(i + 1) Then temp = a(i + 1): a(i + 1) = a(i): a(i) = temp
Next i
Next j
For i = 1 To 10
Print a(i);
Next i
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询