TT/4=1-1/3+1/5-1/7+1/9......1/n
直到:|1/n|接近于0
程序:
# include "math.h"
main()
{double pi=0,n=1,t=1,s=1;
while(fabs(s)>=0.000001)
{pi=pi+s;
t=-t;
n+=2;
s=1.0/n*t;}
pi=pi*4;
printf("%lf",pi);
getch();}
你可以借鉴一下祖冲之的算法,用无穷的切割成正多面形
用估算π/4=1-1/3+1/5-1/7+1/9....