发布网友 发布时间:2022-04-24 00:57
共1个回答
热心网友 时间:2023-10-16 16:57
Private Sub Form_Load()
Dim a(2) As Single
Dim b(4) As Single
Dim c(6) As Single
a(0) = InputBox("请输入第一个数(共3个):")
b(0) = a(0)
c(0) = a(0)
a(1) = InputBox("请输入第二个数(共3个):")
b(1) = a(1)
c(1) = a(1)
a(2) = InputBox("请输入第三个数(共3个):")
b(2) = a(2)
c(2) = a(2)
MsgBox "这三个数中的最大数是:" & Max(a) & ",这三个数中的最小数是:" & Min(a)
b(3) = InputBox("请输入第四个数(共5个):")
c(3) = b(3)
b(4) = InputBox("请输入第五个数(共5个):")
c(4) = b(4)
MsgBox "这五个数中的最大数是:" & Max(b) & ",这五个数中的最小数是:" & Min(b)
c(5) = InputBox("请输入第六个数(共6个):")
c(6) = InputBox("请输入第七个数(共7个):")
MsgBox "这七个数中的最大数是:" & Max(c) & ",这七个数中的最小数是:" & Min(c)
End Sub
Function Max(ByRef a() As Single) As Single '比较一些数找出最大数
Dim i As Integer
Dim b As Single
b = a(0)
For i = 1 To UBound(a)
If b < a(i) Then
b = a(i)
End If
Next
Max = b
End Function
Function Min(ByRef a() As Single) As Single '比较一些数找出最小数
Dim i As Integer
Dim b As Single
b = a(0)
For i = 1 To UBound(a)
If b > a(i) Then
b = a(i)
End If
Next
Min = b
End Function
把代码直接复制到窗体中测试即可