发布网友 发布时间:2022-04-25 15:21
共1个回答
热心网友 时间:2023-10-12 08:32
‘函数过程
Private Sub Command1_Click()
Print max(3, 1, 2) '调用函数
End Sub
Private Function max(x As Integer, y As Integer, z As Integer) As Integer
If x > y Then
If x > z Then max = x Else max = z
Else
If y > z Then max = y Else max = z
End If
End Function
’sub过程
Private Sub Command1_Click()
Dim w() As Integer
n = InputBox("请输入学生数量")
ReDim w(n)
For i = 0 To n
w(i) = Int(100 * Rnd) + 1 '随机对这些学生的成绩赋值
Next
Print
works w '调用sub过程
End Sub
Private Sub works(n() As Integer)
t = 0
For i = LBound(n) To UBound(n)
For j = LBound(n) To UBound(n)
If n(i) > n(j) Then
x = n(i)
n(i) = n(j)
n(j) = x
End If
Next
Next
For i = LBound(n) To UBound(n)
t = t + n(i)
Next
Print "平均值:" & t / (UBound(n) - LBound(n) + 1)
Print "最大值:" & n(LBound(n))
Print "最小值:" & n(UBound(n))
End Sub