将3*3的矩阵转置我编了个程序Private Sub Form_click()Dim a(1 To 3,1 To 3),i As Byte,j As Byte,t As ByteFor i = 1 To 3For j = 1 To 3a(i,j) = Val(InputBox("a(" & i & "," & j & ")=?"))Next jNext iFor i = 2 To 3For j = 1 To i - 1t = a(i,j):a(i,j) = a(j,i):a(j,i) = tNext jNext iFor i = 1 To 3For j = 1 To 3Print a(j,i);Next jPrintNext iEnd Sub为什么输出的还是原来的矩阵,没有转置呢?
问题描述:
将3*3的矩阵转置我编了个程序
Private Sub Form_click()
Dim a(1 To 3,1 To 3),i As Byte,j As Byte,t As Byte
For i = 1 To 3
For j = 1 To 3
a(i,j) = Val(InputBox("a(" & i & "," & j & ")=?"))
Next j
Next i
For i = 2 To 3
For j = 1 To i - 1
t = a(i,j):a(i,j) = a(j,i):a(j,i) = t
Next j
Next i
For i = 1 To 3
For j = 1 To 3
Print a(j,i);
Next j
Print
Next i
End Sub
为什么输出的还是原来的矩阵,没有转置呢?
答
因为你输出时又转置了一下……
For i = 1 To 3
For j = 1 To 3
Print a(j,i);'