设有一个5×5的方阵,其中的元素是随机产生的10~99两位整数.求出主对角线上元素之和、方阵中最大的元素.Option Explicit :Option Base 1Dim a(5,5) As IntegerPrivate Sub Form_Load()Dim i As Integer,j As IntegerDim s As Integer,max As Integer,p As Integer,q As IntegerShowRandomizeFor i = 1 To 5For j = 1 To 5a(i,j) = _____【3】_____Next jNext i_____【4】______ ' 假设第一个元素就是最大的p = 1:q = 1 For i = 1 To 5For j = 1 To 5If ____【5】_____ Then max = a(i,j):p = i:q = jIf i = j Then s = ____【6】_____ ' 主对角线上的元素相加Next jNext

问题描述:

设有一个5×5的方阵,其中的元素是随机产生的10~99两位整数.求出主对角线上元素之和、方阵中最大的元素.
Option Explicit :Option Base 1
Dim a(5,5) As Integer
Private Sub Form_Load()
Dim i As Integer,j As Integer
Dim s As Integer,max As Integer,p As Integer,q As Integer
Show
Randomize
For i = 1 To 5
For j = 1 To 5
a(i,j) = _____【3】_____
Next j
Next i
_____【4】______ ' 假设第一个元素就是最大的
p = 1:q = 1
For i = 1 To 5
For j = 1 To 5
If ____【5】_____ Then max = a(i,j):p = i:q = j
If i = j Then s = ____【6】_____ ' 主对角线上的元素相加
Next j
Next i
Print “主对角线元素之和是:” ; s
Print “方阵中最大的元素是” & "a(" & p & "," & q & ")=" & a(p,q)
End Sub