用VB编写一过程,实现一个二维数组的转置。(数组作为参数)
Private Sub Command1_Click()
Dim a(1 To 3, 1 To 5) As Integer, b(1 To 5, 1 To 3) As Integer
Cls
Print "产生的A数组:"
For i = 1 To 3
For j = 1 To 5
a(i, j) = Int(Rnd * 100)
Print a(i, j);
Next j
Next i
zhuanzhi a, b
Print "转置后的B数组:"
For i = 1 To 5
For j = 1 To 3
Print b(i, j);
Next j
Next i
End Sub
Sub zhuanzhi(ByRef a() As Integer, ByRef b() As Integer)
For i = LBound(a, 1) To UBound(a, 1)
For j = LBound(a, 2) To UBound(a, 2)
b(j, i) = a(i, j)
Next j
Next i
End Sub
2013-07-07
Dim a(1, 2) As Integer
Dim b(2, 1) As Integer
Dim i As Integer
Dim j As Integer
For i = 0 To 1
For j = 0 To 2
a(i, j) = i * 3 + j
Print a(i, j);
Next
Next
Trans a, 2, 3, b
For i = 0 To 2
For j = 0 To 1
Print b(i, j);
Next
Next
End Sub
Private Sub Trans(a() As Integer, m As Integer, n As Integer, b() As Integer)
Dim i As Integer
Dim j As Integer
For i = 0 To n - 1
For j = 0 To m - 1
b(i, j) = a(j, i)
Next
Next
End Sub
2013-07-07