I can't get this program to work.
I am essentially given this series to calculate pi.
π/2 = 1 +1/3+1/32/5+1/32/53/7+...
Here are the steps I was given:
1. [ Set-up ] First term t = 1, Initial sum s = t, term counter n = 1
2. [ Increment term counter ] n = n + 1
3. [ Calculate next term ] New t is old t multiplied by (n-1)/(2n-1)
4. [ Add term to sum ] Add t to s➄
5. [ Are we close enough? ] If t is small we are done: π estimate = 2s
6. [ Loop ] go to ➁ for next term
This is what i have so far:
Code:
#include <stdio.h>
int main()
{// Program for estimate Pi to a given accuracy
// Filename pi.c Src: JWW 2015
int n;float term, small, sum, pi;
printf("Welcome to the pi estimator program\n");
printf( ... );
scanf("%f",&small);
n = 1;
term = 1;
sum = term;
for (;;)
{
n++;
term = t*(n-1)/(2n-1);
sum = t+s;
if (term <= small) break;
}
pi = 2 s;
printf("Our pi estimate is %25.20f\n",pi);
printf("This differs from true pi by %gf\n",
pi-3.141592653589793238462643383279502884197169399375105820974944e0 );
printf("The smallest term included was %g\n", ... );
printf("The number of terms summed was %i\n", ... );}
I'm really confused and just starting off. The ... is where something sould be added but im just not sure. Thanks alot for any help.