[填空题] 如果存在如下过程:Private Function Fun(a() As Integer)Dim First As Integer, Last As Integer,i As In

[填空题] 如果存在如下过程:Private Function Fun(a() As Integer)Dim First As Integer, Last As Integer,i As In,第1张

[填空题] 如果存在如下过程: Private Function Fun(a() As Integer) Dim First As Integer, Last As Integer,i As In

[填空题] 如果存在如下过程:

Private Function Fun(a() As Integer)

Dim First As Integer, Last As Integer,i As Integer

First=LBound(a)

Last=UBound(a)

Max=a(First)

For i=First To Last

If a(i)> Max Then Max=a(i)

Next

Fun=Max

End Function

在窗体上添加一个命令按钮,然后编写如下事件过程:

Private Sub Command1_Click()

ReDim m(1 To 4)As Integer

m(1)=20: m(2)=30: m(3)=50: m(4)=100

c=Fun(m)

Print C

End Sub

单击命令按钮,其输出结果为 (9)

正确答案:

100

参考解析:

在程序Sub中定义了一个含4个元素的数组,并且分别给它们赋值,数组上界是4,下界为1;将数组m作为实参调用Max事件过程,并将数组m的地址传递给数组a,即此时数组a与m共用一个存储空间;将数组的上界和下界分别赋给变量Last和First,在赋值表达式中分别调用了LBound()函数求数组下界及UBound()函数求数组的上界;在循环语句中,变量的初始值为数组的下界为1,终值为数组的上界为4,循环体是一个条件语句,如果a (i)中的值大于Max,就将a(i)的值赋给Max,当循环结束后,将Max作为函数的返回值,所以此事件过程的功能即为求数组中的最大值。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5569766.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-14
下一篇 2022-12-14

发表评论

登录后才能评论

评论列表(0条)

保存