VB 类型不匹配:缺少数组或用户定义类型
PrivateFunctionf2(x()AsSingle,ByValnAsInteger)AsSingleDimiAsIntegerf2=x(1)/nFori=2Ton...
Private Function f2(x() As Single, ByVal n As Integer) As Single
Dim i As Integer
f2 = x(1) / n
For i = 2 To n
f2 = f2 + x(i) / n
Next i
End Function
Private Sub Command1_Click()
Dim n As Single
n = Val(InputBox("输入元素个数"))
ReDim a(n) As Double
For i = 1 To n
a(i) = Val(InputBox("a(" & i & ")="))
Next i
Print f2(a, n)
End Sub
错在哪了..求doble类型一堆数组所有元素的平均值 展开
Dim i As Integer
f2 = x(1) / n
For i = 2 To n
f2 = f2 + x(i) / n
Next i
End Function
Private Sub Command1_Click()
Dim n As Single
n = Val(InputBox("输入元素个数"))
ReDim a(n) As Double
For i = 1 To n
a(i) = Val(InputBox("a(" & i & ")="))
Next i
Print f2(a, n)
End Sub
错在哪了..求doble类型一堆数组所有元素的平均值 展开
1个回答
2014-11-08
展开全部
Private Function f2(x() As Double, ByVal n As Integer) As Single 'x() 后是double
Dim i As Integer
f2 = x(1) / n
For i = 2 To n
f2 = f2 + x(i) / n
Next i
End Function
Private Sub Command1_Click()
Dim n As Single
n = Val(InputBox("输入元素个数"))
ReDim a(n) As Double
For i = 1 To n
a(i) = Val(InputBox("a(" & i & ")="))
Next i
Print f2(a, n)
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询