vb定义一个二维数组,求这个二维数组的最大值、最小值、平均值

一、定义一个二维数组,在屏幕上显示这个二维数组二、定义一个二维数组,求这个二维数组的最大值、最小值、平均值

Private Sub Command1_Click() Dim a(4, 4) As Integer '定义一个5*5的二维数组,下标从0开始 Dim total As Integer, max As Integer, min As Integer Dim i As Integer, j As Integer total = 0 For i = 0 To 4 For j = 0 To 4 a(i, j) = Int(InputBox("请输入数组" & i & ", " & j &"元素值")) If i = 0 And j = 0 Then '初始化max和min值 max = a(i, j) min = a(i, j) Else '否则对max和min值进行比较 If max < a(i, j) Then max = a(i, j) If min > a(i, j) Then min = a(i, j) End If total = total + a(i, j) ‘统计总和 Print a(i, j); Next j Print Next i Print "最大值为:" & max Print "最小值为:" & min Print "平均值为:" & (total / (i * j))End Sub
温馨提示:答案为网友推荐,仅供参考
相似回答