Last active
August 29, 2015 14:06
-
-
Save 0V/e10393f24f2d2a8da1f6 to your computer and use it in GitHub Desktop.
Wallis' Formula by C#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace MathUtil | |
{ | |
/// <summary> | |
/// Wallis の公式 | |
/// </summary> | |
public class WallisFormula | |
{ | |
/// <summary> | |
/// 計算を実行する | |
/// </summary> | |
/// <param name="count">計算回数(この値が大きくなりすぎると死ぬ)</param> | |
/// <returns>計算結果</returns> | |
public static double Compute(int count){ | |
double pi = 1; | |
for (int i = 1; i <= count; i++) | |
{ | |
int n = 4*i*i; | |
pi *= (double)n / (n - 1); | |
} | |
return 2*pi; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment