C# 求Π Π/4=1-1/3+1/5-1/7+......+1/(2*n-3)-1/(2*n-1); (n=2000)
作者:互联网
double a = 0.0;//最终Π的结果 double类型 int n; for (n = 1; n <= 2000; n++) { if (n % 2 == 1) { a += 1.0 / (2 * n - 1); } else { a -= 1.0 / (2 * n - 1); } } a *= 4; Console.WriteLine(a); Console.ReadKey();
注:最终结果与Π的标准值有差别,这是因为误差,吧n设置成200000 精度会更高
标签:200000,C#,double,int,2000,0.0,+......+ 来源: https://www.cnblogs.com/yangyongdashen-S/p/11657149.html