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

则将该元素所在列与第一列对应元素调换。请问编程哪点错了?OptionExplicitOptionBase1Dima(5,5)AsIntegerPrivateSubComm... 则将该元素所在列与第一列对应元素调换。
请问编程哪点错了?
Option Explicit
Option Base 1
Dim a(5, 5) As Integer
Private Sub Command1_Click()
Dim i As Integer, j As Integer
For i = 1 To 5
For j = 1 To 5
a(i, j) = Int(Rnd * 90 + 10)
Picture1.Print a(i, j);
Next j
Picture1.Print
Next i
End Sub

Private Sub Command2_Click()
Dim i As Integer, k As Integer, t As Integer, j As Integer
Call ys(a, k)
If k <> 1 Then
For i = 1 To 5
t = a(i, 1)
a(i, 1) = a(i, k)
a(i, k) = t
Next i
End If
For i = 1 To 5
For j = 1 To 5
Picture2.Print a(i, j);
Next j
Picture2.Print
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
a(i, i) = max: k = i
End If
Next i
End Sub

Private Sub Command3_Click()
Picture1.Cls: Picture2.Cls
Command1.SetFocus
End Sub
展开
 我来答
syx54
2013-10-11 · TA获得超过7378个赞
知道大有可为答主
回答量:6567
采纳率:83%
帮助的人:2734万
展开全部
首先,这个过程有错误:
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
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式