博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
求π【VB代码实现】
阅读量:5256 次
发布时间:2019-06-14

本文共 993 字,大约阅读时间需要 3 分钟。

根据下面的公式,求π

精确到小数后6位。

代码1

Private Sub Command1_Click()    Dim pai As Double, i As Double, item As Double    pai = 0    i = 1    item = 1    Do While item >= 0.000001        pai = pai + (-1) ^ (i - 1) * item        i = i + 1        item = 1 / (2 * i - 1)    Loop    Label2.Caption = Str(4 * pai)End Sub

代码2

Private Sub Command1_Click()    Dim pai As Double, item As Double, i As Double    Dim sign As Integer    pai = 0    i = 1    sign = 1    item = 1    Do While item >= 0.000001        pai = pai + sign * item        sign = sign * -1        i = i + 2        item = 1 / i    Loop    Label2.Caption = Str(4 * pai)End Sub

代码3

Private Sub Command1_Click()    Dim pai As Double, item As Double, i As Double    Dim sign As Integer    pai = 1    i = 1    sign = 1    item = 1    Do While item >= 0.000001        sign = sign * -1        i = i + 2        item = 1 / i        pai = pai + sign * item    Loop    Label2.Caption = Str(4 * pai)End Sub

  

转载于:https://www.cnblogs.com/daveylin/p/6944049.html

你可能感兴趣的文章
Flask三剑客
查看>>
Hibernate-缓存
查看>>
【BZOJ4516】生成魔咒(后缀自动机)
查看>>
提高PHP性能的10条建议
查看>>
svn“Previous operation has not finished; run 'cleanup' if it was interrupted“报错的解决方法...
查看>>
熟用TableView
查看>>
Java大数——a^b + b^a
查看>>
poj 3164 最小树形图(朱刘算法)
查看>>
服务器内存泄露 , 重启后恢复问题解决方案
查看>>
android一些细节问题
查看>>
KDESVN中commit时出现containing working copy admin area is missing错误提示
查看>>
利用AOP写2PC框架(二)
查看>>
【动态规划】skiing
查看>>
java定时器的使用(Timer)
查看>>
ef codefirst VS里修改数据表结构后更新到数据库
查看>>
boost 同步定时器
查看>>
[ROS] Chinese MOOC || Chapter-4.4 Action
查看>>
简单的数据库操作
查看>>
iOS-解决iOS8及以上设置applicationIconBadgeNumber报错的问题
查看>>
亡灵序曲-The Dawn
查看>>