#include
double bailey(int n)
{
double pi = 0;
for(double i = 0; i < n; i++)
pi = pi + (1/(pow(16, i))) * ((4/((8 * i) + 1)- (2/((8 * i) + 4)) - (1/((8 * i) + 5)) - (1/((8 * i)+6))));
return pi;
}
int main()
{
printf("%lf", bailey(10));
return 0;
}
First, verify the formula. I think you need an exponent for 16^k and it must then multiply everything after that.
http://en.wikipedia.org/wiki/Bailey%E2%8...
Write a C function (double bailey (int n);) that calculates pi by using the Bailey-Borwein-Plouffe series where:
pi = sum (as k goes from 0 to infinity) [ (1/16k) * 4/(8k+1) - 2/(8k+4) - 1/(8k+5) - 1/(8k+6) ]
The parameter of the function is the number of the terms in the series to keep.