其他分享
首页 > 其他分享> > 求pi的近似值

求pi的近似值

作者:互联网

求·pi近似值
题目:pi2/6=1/12+1/22+……+1/n2,求pi的近似值

#include<stdio.h>
#include<math.h>
int main()
{
	float pi = 0.0, i = 1.0, n ,s=0.0;
	n=1.0/(i*i);
	while (fabs(n) >= 1e-6)
	{
		n=1.0/(i*i);
		s += n;
		i++;
	}
	pi=sqrt(s*6);
	printf("pi=%10.8f\n", pi);
	return 0;

}

标签:pi,1.0,0.0,include,近似值,main
来源: https://blog.csdn.net/m0_55951222/article/details/114728731