VBb编程 用随机函数给数组元素赋值,然后计算数组元素之和

发布网友 发布时间:2022-04-25 00:03

我来回答

3个回答

热心网友 时间:2023-10-16 13:46

Private Sub Form_Click()
dim aa
aa=0
Dim arr1(10) As Integer, k As Integer, s As Integer
For k = 0 To 10
arr1(k) = Int(Rnd * 900 + 100)
aa=aa+arr1(k)
Next k
Print "数组元素之和为:" + aa
End Sub

如果要在外面来调用,为什么不用函数而用过程呢

Print "数组元素之和为:" + hihi(arr1)

Private function hihi(a)
dim k,b
b=0
for k=0 to 10
b=b+a[k]
next k
hihi=b
end function

热心网友 时间:2023-10-16 13:46

Private Sub Form_Click()

Dim arr1(10) As Integer, k As Integer, s As Integer
For k = 0 To 10
arr1(k) = Int(Rnd * 900 + 100)
Next k
Call abc(arr1, s)
Print "数组元素之和为:" + CStr(s)
End Sub

Private Sub abc(arr2, ByRef ss)

For j = 0 To 10
ss = ss + arr2(j)
Next j

End Sub

热心网友 时间:2023-10-16 13:47

Private Sub Form_Click()
Dim arr1(10) As Integer, k As Integer, s As Integer
For k = 0 To 10
arr1(k) = Int(Rnd * 900 + 100)
Next k
Call hihi(arr1(), s)
Print "数组元素之和为:" + CStr(s)
End Sub

Private Sub hihi(arr2() As Integer, ss As Integer)
For j = 0 To 10
ss = ss + arr2(j)
Next j
End Sub

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com