利用随机函数生成一个由2位正整数构成的4行5列矩阵,求出矩阵行和为最大与最小的行,并掉换这2行的位置
答案:2 悬赏:80 手机版
解决时间 2021-03-31 15:03
- 提问者网友:斑駁影
- 2021-03-30 19:57
利用随机函数生成一个由2位正整数构成的4行5列矩阵,求出矩阵行和为最大与最小的行,并掉换这2行的位置
最佳答案
- 五星知识达人网友:有你哪都是故乡
- 2021-03-30 20:27
Private Sub Command1_Click()
Dim a(1 To 4, 1 To 5) As Integer
Dim i As Integer, j As Integer, max_index As Integer, min_index As Integer
Dim sum_h As Integer, max_h As Integer, min_h As Integer, t As Integer
max_h = 0
min_h = 500
Randomize
For i = 1 To 4
sum_h = 0
For j = 1 To 5
a(i, j) = Int(Rnd * 90) + 10
sum_h = sum_h + a(i, j)
Next j
If sum_h > max_h Then
max_h = sum_h
max_index = i
End If
If sum_h < min_h Then
min_h = sum_h
min_index = i
End If
Next i
Print "原始数组:"
For i = 1 To 4
For j = 1 To 5
Print a(i, j);
Next j
Print
Next i
For j = 1 To 5
t = a(max_index, j)
a(max_index, j) = a(min_index, j)
a(min_index, j) = t
Next j
Print "交换后:"
For i = 1 To 4
For j = 1 To 5
Print a(i, j);
Next j
Print
Next i
End Sub
Dim a(1 To 4, 1 To 5) As Integer
Dim i As Integer, j As Integer, max_index As Integer, min_index As Integer
Dim sum_h As Integer, max_h As Integer, min_h As Integer, t As Integer
max_h = 0
min_h = 500
Randomize
For i = 1 To 4
sum_h = 0
For j = 1 To 5
a(i, j) = Int(Rnd * 90) + 10
sum_h = sum_h + a(i, j)
Next j
If sum_h > max_h Then
max_h = sum_h
max_index = i
End If
If sum_h < min_h Then
min_h = sum_h
min_index = i
End If
Next i
Print "原始数组:"
For i = 1 To 4
For j = 1 To 5
Print a(i, j);
Next j
Next i
For j = 1 To 5
t = a(max_index, j)
a(max_index, j) = a(min_index, j)
a(min_index, j) = t
Next j
Print "交换后:"
For i = 1 To 4
For j = 1 To 5
Print a(i, j);
Next j
Next i
End Sub
全部回答
- 1楼网友:患得患失的劫
- 2021-03-30 22:00
用什么语言呢
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯