VB题:定义一个数组,包含十个两位的随机整数,求出其中的最大值,并在窗体上输出~

VB编程题:定义一个数组,包含十个两位的随机整数,求出其中的最大值,并在窗体上输出~请大虾帮忙做一下

第1个回答  2013-10-27
Private Sub Form_click()
Dim a(1 To 10) As Integer
Print "原始数据是:"
For k = 1 To 10
a(k) = Int(90 * Rnd + 10)
Print a(k);
Next k
Max = a(1)
Print
Print "最大数是:"
For Each x In a
If Max < x Then
Max = x
End If
Next x
Print Max
End Sub本回答被网友采纳
第2个回答  2013-10-27
直接将下面代码复制到窗体中测试即可Private Sub Form_Activate()
Dim a(10) As Integer
Dim k As Integer
Dim Max As Integer
Me.Cls
Print "随机数据如下:"
Max = 0
Randomize
For k = 1 To 10
a(k) = Int(90 * Rnd + 10)
Print a(k) & " ";
If a(k) > Max Then
Max = a(k)
End If
Next
Print vbCrLf & "10个随机数中最大的数是:" & vbCrLf & Max
End Sub
第3个回答  2013-10-27
Private Sub Command1_Click()
Cls
Dim a(1 To 10) As Integer
Dim i As Integer, max As Integer
Randomize
a(1) = Rnd * 90 + 10
max = a(1)
For i = 2 To 10
a(i) = (Rnd * 90 + 10)
If max < a(i) Then max = a(i)
Next i
Print "数组";
For i = 1 To 10
Print a(i);
Next i
Print
Print "最大数是" & max
End Sub
相似回答