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 展开
请问编程哪点错了?
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 展开
展开全部
首先,这个过程有错误:
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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询