求VB编程。设计一个5*5的方阵,其中的元素由计算机随机产生小于100的整数,请求出:1,对角线上元
1个回答
2011-12-09
展开全部
Private Sub Command1_Click()
Dim a(1 To 5, 1 To 5) As Integer
Dim sum, cj, wx, wy, max
Randomize
cj = 1
For i = 1 To 5
For j = 1 To 5
a(i, j) = Int(Rnd * 100)
If i = j Then
sum = sum + a(i, j)
cj = cj * a(i, j)
End If
If a(i, j) > max Then
max = a(i, j)
wx = j: wy = i
End If
Print a(i, j); Tab(5 * j);
Next j
Print
Next i
Print "对角线上元素之和"; sum
Print "对角线上元素之积"; cj
Print "方阵中最大的元素和它的位置"; max, wx; wy
End Sub
Dim a(1 To 5, 1 To 5) As Integer
Dim sum, cj, wx, wy, max
Randomize
cj = 1
For i = 1 To 5
For j = 1 To 5
a(i, j) = Int(Rnd * 100)
If i = j Then
sum = sum + a(i, j)
cj = cj * a(i, j)
End If
If a(i, j) > max Then
max = a(i, j)
wx = j: wy = i
End If
Print a(i, j); Tab(5 * j);
Next j
Next i
Print "对角线上元素之和"; sum
Print "对角线上元素之积"; cj
Print "方阵中最大的元素和它的位置"; max, wx; wy
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询