I need to know how to write a recursive function to calculate pi using the gregory series...based on user input.

For example I'm requesting the user to input the number of terms to calculate pi based on the Gregory series. Please help!

Thank you

For example I'm requesting the user to input the number of terms to calculate pi based on the Gregory series. Please help!

Thank you

First tell me what do You mean by terms

1,2,3,4, etc

or

1,3,5, etc

2.

If Your intension was to stop here You shouldn't call piby4

if (terms==1)

return(piby4(1.0/terms+ter

3.What argument You want to pass to piby4

for example

double fun(int k)

{

if(k==1)

return 13.25;

else

return 54.321;

}

You passing integer and returning double.

{

if (terms==1)

return(piby4(1.0/terms+ter

else if (terms %2==0)

return(piby4(-1.0/terms+te

else if (terms %2)

return(piby4(+1.0/terms+te

else

return (0);

}

--------------------------

Your argument in this call

piby4(1.0/terms+terms-1)

is

1.0/terms+terms-1

and it float

{

if (terms==1)

return(piby4(1.0/terms+ter

else if (terms %2==0)

return(piby4(-1.0/terms+te

else if (terms %2)

return(piby4(+1.0/terms+te

else // it is not necesarry

return (0); // it is not necesarry

}

If You guess what is something it is done and You understand.

Look at the basic formula

for example

piby4(5) should be equivalent to 1/1-1/3+1/5-1/7+1/9 right?

and

piby4(4) should be equivalent to 1/1-1/3+1/5-1/7 right?

so

piby(5) = piby(4) + what

piby4(5) should be equivalent to 1/1-1/3+1/5-1/7+1/9 right?

and

piby4(4) should be equivalent to 1/1-1/3+1/5-1/7 right?

so

piby4(5) = piby4(4) +1/9 right?

Please write me the denominator of the first formula on the page

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.