用VBA编写一个公共的函数Sum(n)=1 + 1/2!+ 1/3!+ 1/4!+ … + 1/n!,n为整型,函数返回值为双精度型.
问题描述:
用VBA编写一个公共的函数Sum(n)=1 + 1/2!+ 1/3!+ 1/4!+ … + 1/n!,n为整型,函数返回值为双精度型.
答
Function isum(n As Integer) As Double
isum = 0
For i = 1 To n
k = 1
For j = 1 To i
k = k * j
Next
isum = isum + 1 / k
Next
End Function