vb 求最大值

来源:百度知道 编辑:UC知道 时间:2024/05/31 02:01:17
编写函数fun,其功能是求一维数组中前n个数的最大值,最大值作为函数返回值。

用VB语言实现:function fun(a() as integer,n as integer) as integer

请提供完整的编程,谢谢

Function fun(a() As Integer, n As Integer) As Integer
Dim i%, max%
For i = 1 To n
max = IIf(a(i) > max, a(i), max)
Next
fun = max
End Function

Private Sub Command1_Click()
Dim tmp%(1 To 30), i%
For i = 1 To 30
tmp(i) = Int(Rnd * 100)
Next

Print fun(tmp(), 10)
End Sub