kumikill
3/23/2016 - 12:35 PM

Returns an approximation of pi using the Leibniz formula.

Returns an approximation of pi using the Leibniz formula.

double LeibnizPi(int limit)
{
  double pi = 0;
  
  for (double n = 0; n <= limit; n++)
  {
    pi += 4 * (Math.Pow(-1, n) / (2 * n + 1));
  }
  
  return pi;
}