早教吧 育儿知识 作业答案 考试题库 百科 知识分享

VB题输入n后,再输入n个数,按照下列公式计算输入n后,再输入n个数a1,a2,a3.,按照下列公式计算s的值并显示.s=(a1+a2+.an)/n

题目详情
VB题输入n后,再输入n个数,按照下列公式计算
输入n后,再输入n个数a1,a2,a3.,按照下列公式计算s的值并显示.
s=(a1+a2+.an)/n
▼优质解答
答案和解析
Private Sub Command1_Click()
Dim n As Integer
Dim i As Integer
Dim a() As Integer
Dim sum As Integer
n = InputBox("请输入多少个数","第一步","10")
ReDim a(n)
For i = 1 To n
a(i) = InputBox("请输入第" & i & "个数","第二步","10")
sum = sum + a(i)
Next
Debug.Print sum / n
End Sub