I want to compute pi using the Spinot's Algorithm of Rabinowitz. It is an infinite sum which consists of two factorials and one power:
The thing is I wrote simple programs for computation of factorials and powers, but I need to combine them in a single for loop. And calculate the sum.
Here's what i did first:
But it is not working. Is it the original idea behind the computation of pi is correct? Is it feasible to compute pi with these series? If yes, what is my mistake here? Any help will be appreciated.Thanks in advance
#include <stdio.h>
int main()
{
float factorialn,n,sqr,power,factoriald,f;
factorialn=1;
n=10;
power=2;
factoriald=1;
for(int i=1;i<=n;i++)
{
factorialn*=i;
}
sqr=factorialn*factorialn;
for(int i=1;i<=n;i++)
{
power=power*2;
}
for(int i=1;i<=2*n+1;i++)
{
factoriald=factoriald*i;
}
printf("factorialn square is: %10f",sqr);
printf("Pow of 2 to the n+1: %10f",power);
printf("Factoriald: %10f",factoriald);
return 0;
}
Second code:
#include <stdio.h>
int main()
{
unsigned long long factorialn,n,sqr,power,factoriald,f;
double sum;
factorialn=1;
n=10;
power=2;
factoriald=1;
for(int i=1;i<=n;i++)
{
factorialn*=i;
power=power*2;
for(int j=1;j<=2*n+1;j++)
{
factoriald=factoriald*j;
}
sum+=factorialn*factorialn*power/factoriald;
}
printf("summa %1.16lf\n;",sum);
return 0;
}