VB编程,求大神帮忙啊,“数组问题”窗口利用随机函数随机产生两个两位数的5×5矩阵并作运算。在线等...
利用随机函数随机产生两个两位数的5×5矩阵并作运算。
要求如下:
(1)将两个矩阵相加,结果放入矩阵C中;(2)统计矩阵C中最大值和下标;
(3)求矩阵A两条对角线元素之和;(4)将矩阵A按列的次序把各元素放入一维数组D中。
(5)结束按钮,返回功能选择界面
设计方法:在窗体上添加4个命令按钮,用来触发有关运算的事件过程;3个图片框,分别用来显示A矩阵、B矩阵及各种运算结果。界面设计见图 展开
Dim a%(1 To 6, 1 To 6), b%(1 To 6, 1 To 6)
Private Sub Command1_Click()
For i = 1 To 5
For j = 1 To 5
a(i, j) = Int(Rnd * 90 + 10)
Picture1.Print a(i, j);
Next j
Picture1.Print
Next i
For i = 1 To 5
For j = 1 To 5
b(i, j) = Int(Rnd * 90 + 10)
Picture2.Print b(i, j);
Next j
Picture2.Print
Next i
End Sub
Private Sub Command2_Click()
Picture3.Cls
Dim c%(1 To 5, 1 To 5), m%, n%, s%
For i = 1 To 5
For j = 1 To 5
c(i, j) = a(i, j) + b(i, j)
If c(i, j) > s Then s = c(i, j): m = i: n = j
Picture3.Print c(i, j);
Next j
Picture3.Print
Next i
Picture3.Print "矩阵C中最大值为" & s & "下标为" & m & "," & n
End Sub
Private Sub Command3_Click()
Dim k%, l%
Picture3.Cls
Picture3.Print "矩阵A左上右下对角元素:"
For i = 1 To 5
Picture3.Print Tab(4 * (i - 1)); a(i, i)
k = k + a(i, i)
Next i
Picture3.Print "元素之和=" & k
Picture3.Print
Picture3.Print "矩阵A右上左下对角元素:"
For i = 1 To 5
Picture3.Print Tab(4 * (5 - i)); a(i, 6 - i)
l = l + a(i, 6 - i)
Next i
Picture3.Print "元素之和=" & l
End Sub
Private Sub Command4_Click()
Dim d%(1 To 25)
Picture3.Cls
For i = 1 To 5
For j = 1 To 5
d(5 * (i - 1) + j) = a(j, i)
Next j
Next i
For i = 1 To 25
Picture3.Print d(i)
Next i
End Sub
广告 您可能关注的内容 |