Private Sub Command1_Click()
Dim I As Integer, N As Integer, Max As Integer, Min As Integer
Min = 100
Randomize
For I = 1 To 20
N = Int(51 * Rnd) + 50
If N > Max Then Max = N
If N < Min Then Min = N
Next I
Print "最大值:"; Max
Print "最小值:"; Min
End Sub
Public Sub 随机数字()
Dim iMin, iMax, n
iMin = 50 '下限
iMax = 100 '上限
n = 20 '个数
'-------先随机 n 个数字,放到数组 A()中
Dim A(), i
ReDim A(1 To n)
For i = LBound(A) To UBound(A)
A(i) = SJsz(iMin, iMax)
Next
'-------求 A()的最大值x、最小值y
Dim x, y
x = A(LBound(A))
y = A(LBound(A))
For i = LBound(A) To UBound(A)
If A(i) > x Then x = A(i)
If A(i) < y Then y = A(i)
Next
'-------显示 最大值x、最小值y
Print "最大值:"; x
Print "最小值:"; y
End Sub
Public Function SJsz(iMin, iMax)
'随机数字函数,iMin:下限; iMax:上限
Randomize
SJsz = Int(Rnd * (iMax - iMin + 1) + iMin)
End Function
Randomize
u = 0
v = 100
For i = 1 To 20
x = 51 + Int(49 * Rnd)
Print x
If u < x Then u = x
If v > x Then v = x
Next i
Print "最大值是"; u
Print "最小值是"; v
Private Sub Command1_Click()
Dim I As Integer, N As Integer, Max As Integer, Min As Integer
Min = 100
Randomize
For I = 1 To 20
N = Int(51 * Rnd) + 50
If N > Max Then Max = N
If N < Min Then Min = N
Next I
Print "最大值:"; Max
Print "最小值:"; Min
End Sub
Private Sub Command1_Click()
Dim i As Integer, n(19) As Integer
Dim max As Integer, min As Integer
max = 0
min = 500
For i = 0 To 19
n(i) = 50 + Int(Rnd * 51)
If n(i) > max Then max = n(i)
If n(i) < min Then min = n(i)
Next
Print max, min
End Sub