求教一道简单的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
求教
展开
 我来答
匿名用户
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
thny
2011-05-11 · TA获得超过1090个赞
知道小有建树答主
回答量:787
采纳率:0%
帮助的人:460万
展开全部
改动这两句,特别是要定义为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
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
手机用户99893
2011-05-12 · TA获得超过251个赞
知道小有建树答主
回答量:742
采纳率:0%
帮助的人:536万
展开全部
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
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式