VB求一组整数的最大值和最小值

VB求一组整数的最大值和最小值

Private Sub MaxAndMin(x%(), ByRef max%, ByRef min%)
    Dim m%, n%, i%
    m = LBound(x): n = UBound(x)
    max = x(m): min = x(m)
    For i = m + 1 To n
        If x(i) > max Then max = x(i)
        If x(i) < min Then min = x(i)
    Next i
End Sub
Private Sub Command1_Click()
    Dim a%(1 To 10), i%, x%, y%
    For i = 1 To 10
        a(i) = Int(Rnd() * 10) '数组元素随机产生
        Print a(i);
    Next i
    Print
    Call MaxAndMin(a, x, y)
    Print "这些数的最大值为:" & x
    Print "这些数的最小值为:" & y
End Sub

VB求一组整数的最大值和最小值_第1张图片

你可能感兴趣的:(VB,开发语言)