vb编程题,随机生成一个(4,5)的矩阵,计算每行的和,找到“和”最大的行于“和最小的”行,互换两行
如:1 2 3 4 5 新矩阵:6 7 8 9 10
6 7 8 9 10 1 2 3 4 5
1 3 5 7 9 1 3 5 7 9
2 4 6 8 10 2 4 6 8 10 展开
Private Sub Command1_Click()
Dim a(4, 5) As Integer
Randomize
Print "原来的数组:"
For i = 1 To 4
s = 0 '不需要时此行可删除
For j = 1 To 5
a(i, j) = Int(Rnd * 100 + 1)
s = s + a(i, j)
Print Tab(4 * j); a(i, j);
Next j
Print "", s '不需要时此行可删除
Next i
Min = 9999
Max = -1
For i = 1 To 4
Sum = 0
For j = 1 To 5
Sum = Sum + a(i, j)
Next j
If Sum > Max Then maxi = i: Max = Sum
If Sum < Min Then Min = Sum: mini = i
Next i
For j = 1 To 5
t = a(maxi, j): a(maxi, j) = a(mini, j): a(mini, j) = t
Next j
Print "交换后的数组:"
For i = 1 To 4
s = 0 '不需要时此行可删除
For j = 1 To 5
Print Tab(4 * j); a(i, j);
s = s + a(i, j)
Next j
Print "", s '不需要时此行可删除
Next i
End Sub