求VB解答。 编写程序,实现矩阵转置,即将一个nⅹm的矩阵的行和列互换。
编写程序,实现矩阵转置,即将一个nⅹm的矩阵的行和列互换。例如:A矩阵及其转置矩阵B分别为:
A=[1 2 3
4 5 6]
[1 4
B= 2 5
3 6]
现要求完成如下操作:
1) 矩阵的行数n和列数m由输入对话框输入;
2) 矩阵中的元素值由输入对话框输入(或由随机数产生);
3) 转置以前的矩阵和转置后的矩阵都在窗体上输出。
Private Sub Command1_Click()
Randomize Timer
Dim n As Integer, m As Integer
Dim arr1() As Integer, arr2() As Integer
Dim i As Integer, j As Integer
n = InputBox("请辩段闷输入矩阵的行数")
m = InputBox("携弯请输入矩燃核阵的列数")
ReDim arr1(1 To n, 1 To m), arr2(1 To m, 1 To n)
For i = 1 To n
For j = 1 To m
arr1(i, j) = Int(Rnd * 10)
Print arr1(i, j);
Next
Print
Next
For i = 1 To m
For j = 1 To n
arr2(i, j) = arr1(j, i)
Print arr2(i, j);
Next
Print
Next
End Sub