有一个按钮command1单机按钮在窗体上输出一个5*5的二维数组,25个数都由一位随机整数构成,要求显示5行5列,求主副对角线上元素之和的差。
Private Sub Command1_Click()
Dim i As Integer, j As Integer, zhu As Integer, fu As Integer
Dim shu(4, 4) As Integer
Randomize
For i = 0 To 4
For j = 0 To 4
shu(i, j) = Int(Rnd * 8) + 1
If i = j Then zhu = zhu + shu(i, j)
If i + j = 4 Then fu = fu + shu(i, j)
Print shu(i, j);
Next
Next
Print "主对角线之和:" + CStr(zhu) + "和副对角线之和:" + CStr(fu) + "之差为:" + CStr(zhu - fu)
End Sub
追问谢谢啦……刚在上课没看到
本回答被提问者采纳