VB编程 计算1-1/2!+1/3!-1/4!+.....+(-1)^(n-1)/n! 要求精度达到0.000001
1个回答
展开全部
Private Sub Command1_Click()
Dim i As Integer, j As Integer
Dim n As Integer
Dim a As Double, s As Double
n = Text1.Text
s = 1#
For i = 2 To n
a = 1#
For j = 2 To i
a = a * j
Next
s = s + ((-1) ^ (i - 1)) / a
Next
Print Round(s, 6)
End Sub
Dim i As Integer, j As Integer
Dim n As Integer
Dim a As Double, s As Double
n = Text1.Text
s = 1#
For i = 2 To n
a = 1#
For j = 2 To i
a = a * j
Next
s = s + ((-1) ^ (i - 1)) / a
Next
Print Round(s, 6)
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询