直接将下面代码复制到窗体中测试即可Private Sub Form_Load() Dim n As Integer Dim a() As Single Dim i As Integer Dim sum As Single Dim even As Single n = CInt(Val(InputBox("请输入数组的存储的数的个数:"))) ReDim a(n) As Single sum = 0 For i = 1 To n a(i) = Val(InputBox("请输入第" & i & "个数(共" & n & "个)")) sum = sum + a(i) Next even = sum / n MsgBox "数组中数的和为" & sum & ",平均数为" & even End Sub
Private Sub Form_click() Dim a(1 To 10) As Integer '定义有10个数据的整型数组 Print "原始数据是:" For k = 1 To 10 a(k) = Int(Rnd * 101) '产生100内的随机整数 Print a(k); Next k For Each x In a Sum = Sum + x Next Print Print "总和是:"; Sum Print "平均数是:"; Sum / 10 End Sub本回答被网友采纳