
VB编程分别用双循环和单循环编写程序计算:1+1/1!-1/2!+1/3!-......+1/(n-1)!-1/n!,当1/n<10^-8时输出结果
1个回答
展开全部
Private Sub Command1_Click()
Dim i As Single, t As Double, s As Double, f As Integer
s = 1
t = 1
f = 1
For i = 1 To 100000000
t = t * i
s = s + f * (1 / t)
f = -f
If t > 100000000 Then Exit For
Next i
Print s
End Sub
以上为单循环
Dim i As Single, t As Double, s As Double, f As Integer
s = 1
t = 1
f = 1
For i = 1 To 100000000
t = t * i
s = s + f * (1 / t)
f = -f
If t > 100000000 Then Exit For
Next i
Print s
End Sub
以上为单循环
追问
求大神给双循环
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询