用随机函数产生10个50以内(包括50)的随机整数存入一维数组。求出最大值并和数组中的首个元素交换位置;输出交换后的所有数组元素。
主要是用VB程序设计
Private Sub Command1_Click()
Randomize
Dim a(9) As Integer, Max As Integer
Dim k As Integer, i As Integer
Dim t As Integer
Max = 0
For i = 0 To 9
a(i) = Int(Rnd * 51)
Print a(i);
If a(i) > Max Then
Max = a(i)
k = i
End If
Next i
Print
If k > 0 Then
t = a(0)
a(0) = a(k)
a(k) = t
End If
For i = 0 To 9
Print a(i);
Next i
Print
Print
End Sub