vb程序里计算1⼀1!+1⼀2!+1⼀3!+1⼀4!+......+1⼀n!????!!

2024年11月14日 15:03
有3个网友回答
网友(1):

Private Sub Command1_Click()
n = Text1.Text
t = 1
For i = 1 To n
t = t * i
s = s + 1 / t
Next i
Text2.Text = s
End Sub

网友(2):

一定有限定条件,不然会出错
比如:n<1000或 1/n!-1<=0.0000001等等

网友(3):

Private Sub Command1_Click()
Dim n As Integer, tmp As Double, sum As Double
Dim i As Integer, j As Integer
n = 4
tmp = 1
For i = 1 To n
For j = 2 To i
tmp = tmp * j
Next
sum = sum + 1 / tmp
tmp = 1
Next
MsgBox sum

End Sub