矩阵转置vb 15
PrivateSubCommand1_Click()Dima()AsIntegern=InputBox("输入行个数")m=InputBox("输入列个数")ReDima...
Private Sub Command1_Click()
Dim a() As Integer
n = InputBox("输入行个数")
m = InputBox("输入列个数")
ReDim a(1 To n, 1 To m)
Randomize
Print "生成矩阵"
For i = 1 To n
For j = 1 To m
a(i, j) = Int(Rnd * 100 + 1)
Print a(i, j);
Next j
Print
Next i
End Sub
Private Sub Command2_Click()
Print "转置"
For i = 1 To n
For j = 1 To m
if i<j then
temp = a(i, j)
a(i, j) = a(j, i)
a(j, i) = temp
end if
Print a(i, j);
Next j
Print
Next i
End Sub 展开
Dim a() As Integer
n = InputBox("输入行个数")
m = InputBox("输入列个数")
ReDim a(1 To n, 1 To m)
Randomize
Print "生成矩阵"
For i = 1 To n
For j = 1 To m
a(i, j) = Int(Rnd * 100 + 1)
Print a(i, j);
Next j
Next i
End Sub
Private Sub Command2_Click()
Print "转置"
For i = 1 To n
For j = 1 To m
if i<j then
temp = a(i, j)
a(i, j) = a(j, i)
a(j, i) = temp
end if
Print a(i, j);
Next j
Next i
End Sub 展开
2个回答
展开全部
Dim a(1, 2) As Integer
Dim i, j As Integer
Dim s1, s2 As String
s1 = "" : s2 = ""
Randomize()
For i = 0 To 1
For j = 0 To 2
a(i, j) = Int(Rnd() * 9) + 1
Next
Next
Dim b(2, 1) As Integer
For i = 0 To 1
For j = 0 To 2
b(j, i) = a(i, j)
s1 += Str(a(i, j))
Next
s1 += Chr(13) + Chr(10)
Next
For i = 0 To 2
For j = 0 To 1
s2 += Str(b(i, j))
Next
s2 += Chr(13) + Chr(10)
Next
MsgBox("a数组为:" + vbCrLf + s1 + vbCrLf + "b数组为:" + vbCrLf + s2)
Dim i, j As Integer
Dim s1, s2 As String
s1 = "" : s2 = ""
Randomize()
For i = 0 To 1
For j = 0 To 2
a(i, j) = Int(Rnd() * 9) + 1
Next
Next
Dim b(2, 1) As Integer
For i = 0 To 1
For j = 0 To 2
b(j, i) = a(i, j)
s1 += Str(a(i, j))
Next
s1 += Chr(13) + Chr(10)
Next
For i = 0 To 2
For j = 0 To 1
s2 += Str(b(i, j))
Next
s2 += Chr(13) + Chr(10)
Next
MsgBox("a数组为:" + vbCrLf + s1 + vbCrLf + "b数组为:" + vbCrLf + s2)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询