-2

如何将二维 a(5,3) 和 b (3,5) 相乘,
所以数组 c( , )= a(5,3) 和 b (3,5)
数组的第一行 a * 数组的列b 然后
数组 a 的第二行 * 数组 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 
4

2 回答 2

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

感谢您的回答

于 2015-01-19T21:43:46.800 回答
0

恭喜!有用 :)

一些评论:

  • 当你使用Dim a, b As Integerthen b 将是一个 Integer,但 a 将是一个 Variant。最好使用Dim a As Integer, b As Integer这样 a 和 b 都是整数
  • 你为什么ReDim c(5, 5) As Integer?您可以使用Dim c(5, 5) As Integer
  • 我不会打印到表单,而是在文本框或标签控件中显示数据
于 2015-01-20T08:16:04.603 回答