早教吧作业答案频道 -->数学-->
利用π/4≈1-1/3+1/5-1/7+…求π得近似值最后一项小于0.000001.我的代码是下面这样,算出来π=2.6667?PrivateSubCommand1Click()DimpAsDouble,nAsLong,tAsInteger,sAsDoublep=1:n=1:t=1Don=n+1s=1/
题目详情
利用π/4≈1-1/3+1/5-1/7+… 求π得近似值 最后一项小于0.000001.我的代码是下面这样,算出来π=2.6667?
Private Sub Command1_Click()
Dim p As Double, n As Long, t As Integer, s As Double
p = 1: n = 1: t = 1
Do
n = n + 1
s = 1 / (2 * n - 1)
t = -t
p = p + t * s
Loop While s < 0.000001
Print 4 * p, p
End Sub
哪里不对,请指出来?我算出来4 * p=2.6666666667.
Private Sub Command1_Click()
Dim p As Double, n As Long, t As Integer, s As Double
p = 1: n = 1: t = 1
Do
n = n + 1
s = 1 / (2 * n - 1)
t = -t
p = p + t * s
Loop While s < 0.000001
Print 4 * p, p
End Sub
哪里不对,请指出来?我算出来4 * p=2.6666666667.
▼优质解答
答案和解析
Loop While s > 0.000001
↑
这里是大于号
↑
这里是大于号
看了 利用π/4≈1-1/3+1/...的网友还看了以下: