d(1,1)
d(1,2)
d(1,3)
d(1,4)
d(2,1)
d(2,2)
d(2,3)
d(2,4)
d(3,1)
d(3,2)
d(3,3)
d(3,4)
通常在程序举纯中对二维数组的 *** 作,采用双重循环来实现,例如求和:
dim
i
as
integer
dim
j
as
integer
dim
S
as
single
S
=
0
for
i=1
to
3
'外循环针对行
for
j=1
to
4
'内循环针对列
S
=
S
+
d(i,j)
next
j
next
i
S
Public Sub add(a() As Integer, b() As Integer, c() As Integer, n As Integer)For i = 1 To n
For j = 1 To n
c(i, j) = a(i, j) + b(i, j)
Next j
Next i
End SubPrivate Sub Command1_Click()
Dim n As Integer
Dim i As Integer, j As Integer
n = InputBox("输入方阵的行数", "输入框")
ReDim a(1 To n, 1 To n)
ReDim b(1 To n, 1 To n)
ReDim c(1 To n, 1 To n)
Call readm(a, "输入矩阵a")
Call readm(a, "输入矩阵b")
Print "矩阵a"
Call out(a)
Print "矩阵b"羡野岩
Call out(b)
Call add(a(), b(), c(), n)
Print "矩阵c"
Call out(c)
End Sub
Public Sub add(a() As Integer, b() As Integer, c() As Integer, n As Integer)
For i = 1 To n
For j = 1 To n
c(i, j) = a(i, j) + b(i, j)
Next j
Next i
End SubPrivate Sub Command1_Click()
Dim n As Integer
Dim i As Integer, j As Integer
n = InputBox("输入方阵的行数", "兄御输入框")
ReDim a(1 To n, 1 To n)
ReDim b(1 To n, 1 To n)
ReDim c(1 To n, 1 To n)
Call readm(a, "输脊岩入矩阵a")
Call readm(a, "输入矩阵b")
Print "矩阵a"
Call out(a)
Print "矩阵b"
Call out(b)
Call add(a(), b(), c(), n)
Print "矩阵c"
Call out(c)
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)