乘以二维数组

时间:2015-01-18 14:00:55

标签: arrays vb6 dimensional

如何乘以二维a(5,3)和b(3,5)
所以arry c(,)= a(5,3)和b(3,5)
第一排arry a * arry b然后列 第二排arry a * arry b的列然后

[编辑] 您的评论代码:

Dim arry1(5, 3) As Integer 
Dim arry2(3, 5) As Integer 
Dim i, j As Integer 
For i = 1 To 5 
  For j = 1 To 3 
    arry1(i, j) = Int(9 * Rnd + 1) 
  Next i, j 
For i = 1 To 3 
  For j = 1 To 5 
    arry2(i, j) = Int(9 * Rnd + 1) 
  Next i, j 

2 个答案:

答案 0 :(得分:0)

Dim a, b As Integer
Dim arry1(5, 3) As Integer
Dim arry2(3, 5) As Integer
ReDim c(5, 5) As Integer
Dim i, j, s As Integer

Print ""
Print Space(15); "the first arry"
Print ""
For i = 1 To 5
  For j = 1 To 3
   arry1(i, j) = Int(9 * Rnd + 1)
   Print Space(3); arry1(i, j);
  Next j
 Print ""
Next i
Print ""
Print Space(15); " the second arry"
Print ""
For i = 1 To 3
  For j = 1 To 5
   arry2(i, j) = Int(9 * Rnd + 1)
   Print Space(3); arry2(i, j);
  Next j
 Print ""
Next i
Print ""
Print Space(15); " the result"
Print ""
cmd1.Visible = False

For a = 1 To 5
   For b = 1 To 5
      For j = 1 To 3
      s = s + (arry1(b, j) * arry2(j, a))
      c(a, b) = s
     Next j
       s=0
  Next b
Next a

For i = 1 To 5
   For j = 1 To 5
    Print Space(3); c(i, j);
   Next j
  Print ""
Next i

谢谢你的答案我解决了这个问题,如果你在我的代码中告诉你的意见,我可能会很高兴...谢谢你

答案 1 :(得分:0)

恭喜!它有效:)

一些意见:

  • 当你使用Dim a, b As Integer时,b将是一个整数,但是一个将是一个变体。最好使用Dim a As Integer, b As Integer,以便a和b都是整数
  • 你为什么ReDim c(5, 5) As Integer?您可以使用Dim c(5, 5) As Integer
  • 我会在文本框或标签控件
  • 中显示数据,而不是打印到表单