vb中:设有一个二维数组A(5,5)编程计算,所有元素的和
2个回答
展开全部
Private Sub Form_Click()
Cls
Randomize
Dim a(5, 5) As Integer
For i = 0 To 5
For j = 0 To 5
a(i, j) = Int(Rnd * 9)
Print a(i, j) & ",";
Sum = Sum + a(i, j)
Next j
Print
Next i
Print "所有元素和为:" & Sum
'////////////
Sum = 0
For i = 0 To 5
Sum = Sum + a(i, 0) + a(i, 5) + a(0, i) + a(5, i)
Next
Sum = Sum - a(0, 0) - a(5, 0) - a(5, 5) - a(0, 5)
Print "所有靠边元素的和:" & Sum
'//////////////////////////////
Sum = 0
For i = 0 To 5
Sum = Sum + a(i, i) + a(i, 5 - i)
Next
Print "两条对角线元素的和为:" & Sum
End Sub
Cls
Randomize
Dim a(5, 5) As Integer
For i = 0 To 5
For j = 0 To 5
a(i, j) = Int(Rnd * 9)
Print a(i, j) & ",";
Sum = Sum + a(i, j)
Next j
Next i
Print "所有元素和为:" & Sum
'////////////
Sum = 0
For i = 0 To 5
Sum = Sum + a(i, 0) + a(i, 5) + a(0, i) + a(5, i)
Next
Sum = Sum - a(0, 0) - a(5, 0) - a(5, 5) - a(0, 5)
Print "所有靠边元素的和:" & Sum
'//////////////////////////////
Sum = 0
For i = 0 To 5
Sum = Sum + a(i, i) + a(i, 5 - i)
Next
Print "两条对角线元素的和为:" & Sum
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询