VB方面的:利用随机函数产生20个50--100范围内的随机数,显示它们的最大值,最小值,和平均值
问题描述:
VB方面的:利用随机函数产生20个50--100范围内的随机数,显示它们的最大值,最小值,和平均值
答
Private Sub Form_click()
Dim n(1 To 20) As Integer
Dim i,j,ave,temp
Randomize
For i = 1 To 20
n(i) = Int((51 * Rnd) + 50)
Print n(i)
Next i
For j = 1 To 19
For i = j + 1 To 20
If n(i) >= n(j) Then
temp = n(i)
n(i) = n(j)
n(j) = temp
End If
Next
Next
ave = 0
For i = 1 To 20
ave = ave + n(i)
Next
ave = ave / 20
Print "最大值为:"; n(1)
Print "最小值为:"; n(20)
Print "平均值为:"; ave
End Sub