能用vb的知识回答: . 编写程序:6. 用两种不同的方法求1+1⼀1!+1⼀2!+1⼀3!+…+1⼀n!

2025-01-03 17:56:18
推荐回答(1个)
回答1:

Private Sub Command1_Click()
Dim i, t, s
s = 1
For i = 1 To 50
s = s + 1 / fc(i)
Next
Print s, i
End Sub
Private Sub Command2_Click()
Dim s, i, k
s = 1
Do
i = i + 1
k = 1 / fc(i)
If k < 10 ^ (-6) Then Exit Do
s = s + k
Loop
Print s, i - 1
End Sub
Function fc(n)
Dim i
fc = 1
For i = 1 To n
fc = fc * i
Next
End Function