Below is a simple "C" program for calculating low values of n
#include <iostream> #include <cmath> int main() { double p16 = 1, pi = 0, precision = 10; for(int k=0; k<=precision; k++) { pi += 1.0/p16 * (4.0/(8*k + 1) - 2.0/(8*k + 4) - 1.0/(8*k + 5) - 1.0/(8*k+6)); p16 *= 16; } std::cout<<std::setprecision(80)<<pi<<'\n'<<M_PI; }
Output:
3.141592653589793115997963468544185161590576171875 3.141592653589793115997963468544185161590576171875
To start at nth digit change the value of k