VB 用随机数(20~80)生成一个4行4列的矩阵A,求A的转置矩阵

PrivateSubPicture1_Click()Dima(4,4)AsInteger,iAsInteger,jAsIntegerFori=1To4Forj=1To4a... Private Sub Picture1_Click() Dim a(4, 4) As Integer, i As Integer, j As IntegerFor i = 1 To 4For j = 1 To 4a(i, j) = Int(Rnd() * 61 + 20)Picture1.Print a(i, j);NextPicture1.PrintNextPicture1.Print
End Sub
展开
 我来答
听不清啊
高粉答主

推荐于2018-04-12 · 说的都是干货,快来关注
知道顶级答主
回答量:7.8万
采纳率:89%
帮助的人:2亿
展开全部

已经完成:

Private Sub Picture1_Click()

 Dim a(4, 4) As Integer, i As Integer, j As Integer, b(4, 4) As Integer

For i = 1 To 4

For j = 1 To 4

a(i, j) = Int(Rnd() * 61 + 20)

Picture1.Print a(i, j);

Next

Picture1.Print

Next

Picture1.Print


For i = 1 To 4

For j = 1 To 4

b(i, j) = a(j, i)

Picture1.Print b(i, j);

Next

Picture1.Print

Next

Picture1.Print


End Sub

追问
如果。。我想把转置的放在picture2呢??单击“命令按钮转置”然后picture2出现picture1的矩阵的转置
追答
Dim a(4, 4) As Integer
Private Sub Picture1_Click()
Dim i As Integer, j As Integer
For i = 1 To 4
For j = 1 To 4
a(i, j) = Int(Rnd() * 61 + 20)
Picture1.Print a(i, j);
Next
Picture1.Print
Next
Picture1.Print

End Sub

Private Sub Command1_Click()
Dim b(4, 4) As Integer
For i = 1 To 4

For j = 1 To 4
b(i, j) = a(j, i)
Picture2.Print b(i, j);
Next
Picture2.Print
Next
Picture2.Print
End Sub
来自:求助得到的回答
百度网友b32a2aeee
2014-04-27 · 超过34用户采纳过TA的回答
知道答主
回答量:66
采纳率:0%
帮助的人:48.5万
展开全部
我懒得给你重写,直接给你一个转置的函数,调用形式:bt = MatTrn(B),B为输入矩阵,bt为输出结果


Public Function MatTrn(x() As Double) As Double()

    Dim n As Long

    Dim m As Long

    Dim i As Long

    Dim j As Long, y() As Double

    n = UBound(x, 1)

    m = UBound(x, 2)

    'If Not IsDimed(Y) Then

        ReDim y(1 To m, 1 To n)

    'End If

    'ReDim Y(1 To m, 1 To n) As Double

    For i = 1 To n

        For j = 1 To m

            y(j, i) = x(i, j)

        Next j

    Next i

    MatTrn = y

End Function

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
jixiexueyuan09
2014-04-27
知道答主
回答量:8
采纳率:0%
帮助的人:2.6万
展开全部
要是只是显示的话,只需要一列一列输出就好!代码如下
For j= 1 To 4
For i= 1 To 4

Picture2.Print a(i, j);
Next
Picture2.Print
Next
Picture2.Print
要是想得到A的转置矩阵,代码如下:
dim b(4,4) as integer
For j= 1 To 4
For i= 1 To 4
b(j,i)=a(i, j) ;
Next

Next
追问
Private Sub Picture1_Click()
这是矩阵A出现的代码
End Sub
然后
Private Sub command1_Click()
这是转置的代码,但是这样的话,上面的a(i,j)就会因程序结束而回到初始值。。不能用在这里。。是不是会这样啊?我不太懂啊?
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式