C语言:计算圆周率(精度保留到小数点后6位),用程序实现,公式如下:

如题所述

#include<stdio.h>

#include<math.h>

int main()

{double pi=1,t=0;

 for(;t<1.9999999;)

 {t=sqrt(2+t);

  pi*=2/t;

  }

  printf("%lf\n",pi*2);

 return 0;

}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-12-13
#include "math.h"
float pi(){
float l = sqrt(2);
float lp = 0;
float p = 4.0 / l;
while (fabs(p - lp) > 1e-6) {
l = sqrt(2+l);
lp = p;
p = 2*p/l;
}
return p;
}
int main()
{
printf("%f", pi());
return 0;
}

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网