Skip to content

Instantly share code, notes, and snippets.

@0V
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0V/e10393f24f2d2a8da1f6 to your computer and use it in GitHub Desktop.
Save 0V/e10393f24f2d2a8da1f6 to your computer and use it in GitHub Desktop.
Wallis' Formula by C#
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