求教一道简单的VB题,直到最后一项的绝对值小于10-5为止。 1-1/(1*2)+1/(2*3)-
我的答案,不知道哪里错了PrivateSubCommand1_Click()DimaAsDouble,iAsInteger,sAsSinglef=-1i=1Doa=1/(...
我的答案,不知道哪里错了Private Sub Command1_Click()
Dim a As Double, i As Integer, s As Single
f = -1
i = 1
Do
a = 1 / (i * (i + 1))
s = 1 + f * a
i = i + 1
f = -f
Loop Until Abs(a) < 10 ^ (-5)
Print s
End Sub
求教 展开
Dim a As Double, i As Integer, s As Single
f = -1
i = 1
Do
a = 1 / (i * (i + 1))
s = 1 + f * a
i = i + 1
f = -f
Loop Until Abs(a) < 10 ^ (-5)
Print s
End Sub
求教 展开
3个回答
2011-05-11
展开全部
Private Sub Command1_Click()
Dim a As Double, i As Long, s As Single
f = -1
i = 1
Do
a = 1 / (i * (i + 1))
s = 1 + f * a
i = i + 1
f = -f
Loop Until Abs(a) < 10 ^ (-5)
Print s
End Sub
Dim a As Double, i As Long, s As Single
f = -1
i = 1
Do
a = 1 / (i * (i + 1))
s = 1 + f * a
i = i + 1
f = -f
Loop Until Abs(a) < 10 ^ (-5)
Print s
End Sub
展开全部
改动这两句,特别是要定义为Variant即可
Dim a As Variant, s As Variant, i As Variant
s = s + f * a
程序:
Private Sub Command1_Click()
Dim a As Variant, s As Variant, i As Variant
f = -1
i = 1
s = 1
Do
a = 1 / (i * (i + 1))
s = s + f * a
i = i + 1
f = -f
Loop Until Abs(a) < 10 ^ (-5)
Print S
End Sub
Dim a As Variant, s As Variant, i As Variant
s = s + f * a
程序:
Private Sub Command1_Click()
Dim a As Variant, s As Variant, i As Variant
f = -1
i = 1
s = 1
Do
a = 1 / (i * (i + 1))
s = s + f * a
i = i + 1
f = -f
Loop Until Abs(a) < 10 ^ (-5)
Print S
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Public Function MyCos(ByVal x As Double) As Double
Dim i As Integer, sum As Double, a As Double
i = 2
sum = 1
a = 1
Do
a = -a * x * x / i / (i - 1)
sum = sum + a
i = i + 2
Loop Until Abs(a) < 10 ^ -7
MyCos = sum
End Function
Dim i As Integer, sum As Double, a As Double
i = 2
sum = 1
a = 1
Do
a = -a * x * x / i / (i - 1)
sum = sum + a
i = i + 2
Loop Until Abs(a) < 10 ^ -7
MyCos = sum
End Function
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询