Private Sub Form_Click()
Dim n, m, i, j, Matrix(), Cache() As Integer
n = CInt(InputBox("请输入矩阵行数N", "矩阵置换"))
m = CInt(InputBox("请输入矩阵列数M", "矩阵置换"))
ReDim Matrix(n - 1, m - 1)
ReDim Cache(m - 1, n - 1)
'录入
For i = 0 To n - 1
For j = 0 To m - 1
Matrix(i, j) = CInt(InputBox("请输入矩阵项(" & (i + 1) & "," & (j + 1) & ")", "矩阵置换"))
Next
Next
'转置
For i = 0 To n - 1
For j = 0 To m - 1
Cache(j, i) = Matrix(i, j)
Next
Next
'输出转置前的矩阵
Print "转置前的矩阵为:"
For i = 0 To n - 1
For j = 0 To m - 1
Print Matrix(i, j);
Next
Print
Next
Print
'输出转置后的矩阵
Print "转置后的矩阵为:"
For i = 0 To m - 1
For j = 0 To n - 1
Print Cache(i, j);
Next
Print
Next
End Sub
温馨提示:答案为网友推荐,仅供参考