**Tags**

The below program I developed to calculate the first 10,000 digits of π. This is C# and using `BigInteger`

class.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Numerics;

using System.Text;

using System.Threading.Tasks;

namespace PrintPI

{

class Program

{

static void Main(string[] args)

{

//Console.WriteLine(2 * F(1));

string lines = GetPi(10000, 100).ToString();

int nInterval = 50;

string res = String.Concat(lines.Select((c, i) => i > 0 && (i % nInterval) == 0 ? c.ToString() + Environment.NewLine : c.ToString()));

Console.WriteLine(GetPi(10000,100).ToString());

System.IO.File.WriteAllText(@”C:UsersIsham MohamedDesktopPI.txt”, res);

Console.ReadLine();

}

public static BigInteger GetPi(int digits, int iterations)

{

return 16 * ArcTan1OverX(5, digits).ElementAt(iterations)

– 4 * ArcTan1OverX(239, digits).ElementAt(iterations);

}

//arctan(x) = x – x^3/3 + x^5/5 – x^7/7 + x^9/9 – …

public static IEnumerable<BigInteger> ArcTan1OverX(int x, int digits)

{

var mag = BigInteger.Pow(10, digits);

var sum = BigInteger.Zero;

bool sign = true;

for (int i = 1; true; i += 2)

{

var cur = mag / (BigInteger.Pow(x, i) * i);

if (sign)

{

sum += cur;

}

else

{

sum -= cur;

}

yield return sum;

sign = !sign;

}

}

}

}

Here you can find the digits.

Advertisements