vb生成5行5列数组 求行和与列和 5
1个回答
展开全部
Option Base 1
Private Sub Form_Click()
Dim a%(5, 5)
P1.Cls
Randomize
For i = 1 To 5
For j = 1 To 5
a(i, j) = Int(Rnd * 10) '数组元素赋值
P1.Print a(i, j); '数组元素输出
Next
P1.Print
Next
sum1 = 0
sum2 = 0
sum3 = 0
For i = 1 To 5
For j = 1 To 5
sum1 = sum1 + a(i, j) '所有元素之和
If i = 1 Or i = 5 Or j = 1 Or j = 5 Then '靠伍丛边元素
sum2 = sum2 + a(i, j)
End If
If i = j Or i + j = 6 Then '对角线元素
sum3 = sum3 + a(i, j)
End If
Next
Next
P1.Print "所有元派拿素之和为"; sum1
P1.Print "靠边腔羡樱元素之和为"; sum2
P1.Print "两条对角线元素之和为"; sum3
Private Sub Form_Click()
Dim a%(5, 5)
P1.Cls
Randomize
For i = 1 To 5
For j = 1 To 5
a(i, j) = Int(Rnd * 10) '数组元素赋值
P1.Print a(i, j); '数组元素输出
Next
P1.Print
Next
sum1 = 0
sum2 = 0
sum3 = 0
For i = 1 To 5
For j = 1 To 5
sum1 = sum1 + a(i, j) '所有元素之和
If i = 1 Or i = 5 Or j = 1 Or j = 5 Then '靠伍丛边元素
sum2 = sum2 + a(i, j)
End If
If i = j Or i + j = 6 Then '对角线元素
sum3 = sum3 + a(i, j)
End If
Next
Next
P1.Print "所有元派拿素之和为"; sum1
P1.Print "靠边腔羡樱元素之和为"; sum2
P1.Print "两条对角线元素之和为"; sum3
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询