vb产生30个0~1000的随机整数,放入一个数组中,输出最大值
3个回答
展开全部
'实现代码如下
Private Sub Form_Click()
Me.Cls
Dim n(1 To 30) As Integer
Dim i%,nMax%
Dim str As String
'产生30个0-1000的随机数并写入数组
Randomize
For i = 1 To 30
n(i) = Int((1000 - 0 + 1) * Rnd + 0)
str = str & n(i) & " "
If i Mod 10=0 Then str=str & vbCrLf
Next i
'找最大值
nMax=n(1)
For i = 1 To 30
If n(i)>nMax Then nMax=n(i)
Next i
Print str '窗体显示随机数
Print "最大值:" & nMax
End Sub
展开全部
'实现代码如下
Private Sub Form_Click()
Me.Cls
Dim n(1 To 30) As Integer
Dim i%,nMax%
Dim str As String
'产生30个0-1000的随机数并写入数组
Randomize
For i = 1 To 30
n(i) = Int((1000 - 0 + 1) * Rnd + 0)
str = str & n(i) & " "
If i Mod 10=0 Then str=str & vbCrLf
Next i
'找最大值
nMax=n(1)
For i = 1 To 30
If n(i)>nMax Then nMax=n(i)
Next i
Print str '窗体显示随机数
Print "最大值:" & nMax
End Sub
Private Sub Form_Click()
Me.Cls
Dim n(1 To 30) As Integer
Dim i%,nMax%
Dim str As String
'产生30个0-1000的随机数并写入数组
Randomize
For i = 1 To 30
n(i) = Int((1000 - 0 + 1) * Rnd + 0)
str = str & n(i) & " "
If i Mod 10=0 Then str=str & vbCrLf
Next i
'找最大值
nMax=n(1)
For i = 1 To 30
If n(i)>nMax Then nMax=n(i)
Next i
Print str '窗体显示随机数
Print "最大值:" & nMax
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询