VB编程题 随机生成5×5二维数组 并输出每行元素的最大值 平均值 和所有
1个回答
展开全部
Private Sub Command1_Click()
Dim a(1 To 5, 1 To 5) As Integer, intSum(1 To 5) As Integer, intMax(1 To 5) As Integer
Dim intMaxID(1 To 5) As Integer, intMax1 As Integer, intMaxRowID As Integer, intMaxColumnID As Integer
Print " 二维数组 "; "最大值"; " 平均数"
Randomize (Timer)
For i = 1 To 5
For j = 1 To 5
a(i, j) = Int(Rnd * 900 + 100)
If a(i, j) > intMax(i) Then
intMax(i) = a(i, j)
intMaxID(i) = j
End If
intSum(i) = intSum(i) + a(i, j)
Print a(i, j);
Next j
If intMax(i) > intMax1 Then
intMax1 = intMax(i)
intMaxRowID = i
intMaxColumnID = intMaxID(i)
End If
Print Space(4) & intMax(i) & Space(4) & intSum(i) / 5
Next i
Print " 所有元素最大值" & intMax1 & "的行号为" & intMaxRowID; ",列号为" & intMaxColumnID & "。"
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询