首页  >  Word

求三维数组包含的元素个数

Word 2024-04-15 13:00:11 32

本文为:随书问题参考答案

下面是解决本例问题的参考过程:

Sub 求三维数组的元素个数()
'=====以下代码用于声明三维数组并给三维数组赋值
Dim arr(1 To 3, 1 To 5, 1 To 10) As Integer
Dim i As Integer, j As Integer, k As Integer, m As Integer
For i = 1 To 3
For j = 1 To 5
For k = 1 To 10
m = m + 1
arr(i, j, k) = m
Next
Next
Next
'====以下代码用于求三维数组中的元素个数
'****求数组第1维的最大和最小索引号
Dim a As Integer, b As Integer
a = UBound(arr, 1)
b = LBound(arr, 1)
'****求数组第2维的最大和最小索引号
Dim c As Integer, d As Integer
c = UBound(arr, 2)
d = LBound(arr, 2)
'****求数组第3维的最大和最小索引号
Dim e As Integer, f As Integer
e = UBound(arr, 3)
f = LBound(arr, 3)
'****用对放框显示数组的元素个数
MsgBox "数组包含的元素个数是:" & (a - b + 1) * (c - d + 1) * (e - f + 1)
End Sub

三维数组
版权声明

本文来自投稿,不代表本站立场,转载请注明出处。

分享:

扫一扫在手机阅读、分享本文