VB编程,随机生成5行5列的两位正整数数组,找出数组主对角线上最大元素所在列号,若最大元素不在第一列,

2025-06-27 01:19:14
推荐回答(1个)
回答1:

首先,这个过程有错误:
Private Sub ys(a() As Integer, k As Integer)
Dim i As Integer, max As Integer
max = a(1, 1): k = 1
For i = 1 To 5
If max < a(i, i) Then
a(i, i) = max: k = i
End If
Next i
End Sub
改成
Private Sub ys(a() As Integer, k As Integer)
Dim i As Integer, max As Integer
max = a(1, 1): k = 1
For i = 1 To 5
If max < a(i, i) Then
max = a(i, i) : k = i
End If
Next i
End Sub