用VB求表达式的值
y=1/1!+1/2!+1/3!+……+1/n!直到n!小于0.00001为止。我做出来都是(1/n)!的形式,如何输出1/n!的形式?...
y=1/1!+1/2!+1/3!+……+1/n! 直到n! 小于0.00001为止。我做出来都是(1/n)!的形式,如何输出1/n!的形式?
展开
1个回答
展开全部
如果n为正整数n!永远不会小于0.00001,应该是1/n!小于0.00001吧?
如果是的,用下面程序:
Private Sub Form_Load()
Dim i As Long
i = 1
Dim njc As Double
Do While getNjc(i) >= 0.00001
njc = njc + getNjc(i)
i = i + 1
Loop
MsgBox njc
End Sub
Private Function getNjc(n As Long) As Double
Dim k As Double
k = 1
For i = 1 To n
k = k * i
Next
getNjc = 1 / k
End Function
如果是的,用下面程序:
Private Sub Form_Load()
Dim i As Long
i = 1
Dim njc As Double
Do While getNjc(i) >= 0.00001
njc = njc + getNjc(i)
i = i + 1
Loop
MsgBox njc
End Sub
Private Function getNjc(n As Long) As Double
Dim k As Double
k = 1
For i = 1 To n
k = k * i
Next
getNjc = 1 / k
End Function
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询