请教一道VB题,关于行列互换

来源:百度知道 编辑:UC知道 时间:2024/05/16 23:52:24
输入N(N>=3)建立一个两维数组(例如3×3,4×4……),在窗体上输入该数组后,转置数组(行列互换)后再次输出数组。
能不能提供代码参考下
Private Sub Command1_Click()
Dim i As Integer, j As Integer, N As Integer
N = Val(InputBox("请输入N(N>=3):"))
ReDim a(N, N) As Integer
Dim row As Integer, col As Integer
Print "原数据组:"
Randomize
For i = 1 To N
For j = 1 To N
a(i, j) = Int(Rnd * 100 + 1)
Print a(i, j),
Next j
Print
Next i

End Sub
(第一步给出一个二位数据组我是这样做得,然后再通过Command2_Click转换的代码怎么编写?)
Private Sub Command2_Click()

或者是用sub过程来做吗?但是我这课没去上,不知道怎么写。。。==

开始转换:
接你的程序:

private sub command2_click()
dim k() as integer
redim k(n,n) as integer
for i=0 to n
for j=0 to n
k(i,j)=a(j,i)
next
next
for i=0 to n
for j=0 to n
print k(i,j);
next
print
next
end sub

dim a() as double
dim N as integer,i%,j%
N=inputbox("Input the Number that you intend to define the array")
redim a(N,N)
for i=0 to N-1
for j=0 to N-1
a(i,j)=inputbox("input the value of a ( "& i & "," & j & ")")
me.print a(i,j);

next j
me.print
next i
for i=0 to N-1
for j=i to N-1
if i<>j then

a(i,j)=a(j,i)+a(i,j)
a(j,i)=a(i,j)-a(j,i)
a(i,j)=a(i,j)-a(j,i)
end if
me.print a(i,j)
next j
me.print
next i

Private Sub Form_Click()
Dim A() As Long, N As Inte