VB程序,设有一个二维数组A(4,5),其中每个元素均由两位随机整数构成,然后执行以下操作:
(1)在图片框一中输出该数组(2)交换第一列和第三列(3)求出矩阵行的和伟最大和最小的行,并交换这两行的位置(4)在图片框二中输出处理后的数组...
(1)在图片框一中输出该数组
(2)交换第一列和第三列
(3)求出矩阵行的和伟最大和最小的行,并交换这两行的位置
(4)在图片框二中输出处理后的数组 展开
(2)交换第一列和第三列
(3)求出矩阵行的和伟最大和最小的行,并交换这两行的位置
(4)在图片框二中输出处理后的数组 展开
1个回答
展开全部
Private A(1 To 4, 1 To 5) As Integer
Private Sub SwitchArrE(ByVal AIndex As Integer, ByVal BIndex As Integer)
Dim i, k As Integer
For i = 1 To 5
k = A(AIndex, i)
A(AIndex, i) = A(BIndex, i)
A(BIndex, i) = k
Next i
End Sub
Private Sub Command1_Click()
Dim i, j, iMax, iMin, iMaxIndex, iMinIndex, iSum As Integer
Randomize
For i = 1 To 4
iSum = 0
For j = 1 To 5
k = Int(Rnd * 100)
If k < 10 Then k = k + 10
A(i, j) = k
iSum = iSum + k
Next j
'打印数组
Picture1.Print A(i, 1), A(i, 2), A(i, 3), A(i, 4), A(i, 5)
Next i
'交换第一和第三列
SwitchArrE 1, 3
'计算最大行和最小行
For i = 1 To 4
k = 0
For j = 1 To 5
k = A(i, j) + k
Next j
If i = 1 Then
iMax = k
iMin = k
iMaxIndex = i
iMinIndex = i
Else
If k > iMax Then
iMax = k
iMaxIndex = i
Else
If k < iMin Then
iMin = k
iMinIndex = i
End If
End If
End If
Next i
'交换最大和最小行
SwitchArrE iMaxIndex, iMinIndex
'打印处理后的数组
For i = 1 To 4
Picture2.Print A(i, 1), A(i, 2), A(i, 3), A(i, 4), A(i, 5)
Next i
End Sub
Private Sub SwitchArrE(ByVal AIndex As Integer, ByVal BIndex As Integer)
Dim i, k As Integer
For i = 1 To 5
k = A(AIndex, i)
A(AIndex, i) = A(BIndex, i)
A(BIndex, i) = k
Next i
End Sub
Private Sub Command1_Click()
Dim i, j, iMax, iMin, iMaxIndex, iMinIndex, iSum As Integer
Randomize
For i = 1 To 4
iSum = 0
For j = 1 To 5
k = Int(Rnd * 100)
If k < 10 Then k = k + 10
A(i, j) = k
iSum = iSum + k
Next j
'打印数组
Picture1.Print A(i, 1), A(i, 2), A(i, 3), A(i, 4), A(i, 5)
Next i
'交换第一和第三列
SwitchArrE 1, 3
'计算最大行和最小行
For i = 1 To 4
k = 0
For j = 1 To 5
k = A(i, j) + k
Next j
If i = 1 Then
iMax = k
iMin = k
iMaxIndex = i
iMinIndex = i
Else
If k > iMax Then
iMax = k
iMaxIndex = i
Else
If k < iMin Then
iMin = k
iMinIndex = i
End If
End If
End If
Next i
'交换最大和最小行
SwitchArrE iMaxIndex, iMinIndex
'打印处理后的数组
For i = 1 To 4
Picture2.Print A(i, 1), A(i, 2), A(i, 3), A(i, 4), A(i, 5)
Next i
End Sub
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询