VB求平均值

VB求平均值

Private Function pj(x() As Integer) As Single
    Dim m%, n%, i%, s%
    m = LBound(x): n = UBound(x)
    For i = m To n
        s = s + x(i)
    Next i
    pj = s / (n - m + 1)
End Function
Private Sub Command1_Click()
    Dim a%(1 To 10), i%, aver!
    For i = 1 To 10
        a(i) = Int(Rnd() * 10) '随机元素的值随机产生
        Print a(i);
    Next i
    Print
    aver = pj(a)
    Print "这些数的平均值为:" & aver
End Sub

VB求平均值_第1张图片

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