求π: π/4=1-1/3+1/5-1/7+...+1/(4n-3)-1/(4n-1),n=10000 VB编程...
用fuction定义...
大家给说说啊
求π: π/4=1-1/3+1/5-1/7+...+1/(4n-3)-1/(4n-1),n=10000 VB编程
答案:3 悬赏:50 手机版
解决时间 2021-02-18 02:47
- 提问者网友:欲劫无渡
- 2021-02-17 19:59
最佳答案
- 五星知识达人网友:蓝房子
- 2021-02-17 20:56
Private Sub Command1_Click()
'这里调用求pi函数,
p = pi(10000)
'p即为所求``
End Sub
''下面是求pi的函数
Private Function pi(ByVal n As Long) As Double
For i = 1 To 2 * n - 1
pi = pi + 1 / (4 * i - 3) - 1 / (4 * i - 1)
Next i
pi = 4 * pi
End Function
'这里调用求pi函数,
p = pi(10000)
'p即为所求``
End Sub
''下面是求pi的函数
Private Function pi(ByVal n As Long) As Double
For i = 1 To 2 * n - 1
pi = pi + 1 / (4 * i - 3) - 1 / (4 * i - 1)
Next i
pi = 4 * pi
End Function
全部回答
- 1楼网友:duile
- 2021-02-17 23:03
汗 书本不是有代码吗 运行结果π=3.141499 Function pai(n As Single)
Dim i, t, e
e = 1
'π/4=1-1/3+1/5-1/7+...+1/(4n-3)-1/(4n-1),n=10000 VB编程...
For i = 1 To n
t = 1 / (2*i-1)
pai = pai + t * e
e = e * (-1)
Next i
Text1 = "π=" & 4 * pai
End Function
Private Sub Form_Load()
pai (10000)
End Sub
- 2楼网友:舊物识亽
- 2021-02-17 21:58
private sub command1_click() dim x as double dim sum as double dim sum1 as double dim sum2 as double sum1 = 1 for i = 1 to 10000 x = (1 / (4 * i - 1)) y = (1 / (4 * (i + 1) - 3)) sum1 = sum1 + x sum2 = sum2 + y next i sum=sum1-sum2 label1.caption = sum end sub
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯