ok i have 2 series of p...
the user give which one was want...
and then give the iterations that he/she want

this is the series
4. P= sqrt(8*(1+ (1/9)+(1/25)+(1/49)+... ))
5. P= sqrt(24*((1/4)+(1/16)+(1/36)+(1/64)+...))

code::
first for series 4.....

int i;
double: serieValue=0,pi=0;
cout<<"Iterations";
cin>>i;
for (long int n = 1; n <= i; n++)
{
serieValue+= pow(+1.0, n+1)/pow(n*n,2.0);
} 
pi=sqrt(8*serieValue);
cout << "Estimated PI value  "<< pi<<endl;

code:::
for series 5.....

int i;
cout<<"Iterations: ";
cin>>i;
double: serieValue=0,pi=0;
for (long int n = 1; n <= i; n++)
{
serieValue+= pow(+1.0, n+1)/pow(n*n+2,2.0);
} 
pi=sqrt(24*serieValue);
cout << "Estimated PI value  "<< pi<<endl;

But isn't works....Please any ideas to fixed it this problem???

Thank you very much

What do you mean it "isn't works"?

Do you get a compiler error, is the output completely wrong, is it just wrong by a bit. Tell us what you mean.

> First calculate the whole number where you want to take the square root from (calculate the sum of the first n elements of the series)

>> Formula for the first series: (1/9)+(1/25)+(1/49)+... => 1/((3+(n-1)*2)^2) (n represents the nth element of the series :) ...)

>> Formula for the second series: (1/4)+(1/16)+(1/36)+(1/64)+... => 1/((2+(n-1)*2)^2) Now you've the formulas to calculate the nth element of both series it will be a lot easier to implement it I think :P ...

no syntax error.... program start.... but if i try to calculating the
series 4 with 1000 iterations takes 2.94255 so, it must be 3.14******
the same thing as
series 5 with 1000 iterations takes 2.54832 so,it's the same thing the results must be 3.14****

"n" is the counter for " for loop " if you see n=1; n<=i; (that i = 5)
make 1000 the equations... so if you set the n = 5 that you say.. (n = series 5 ) then if the user add iterations 4 then the results it's 0... i don't know the results of 1 iterations.... if you comparing this 5 series
with 5 iterations you must have alsmost the same result....
3.14******(*=others numbers)

>>pow(+1.0, n+1)/pow(n*n,2.0);
How does (1/9) translate to the above equation? When n = 1, the above will be pow(1,2) / pow(1,2) which is 1^2/1^2 = 1. When n = 2, we get pow(1,3)/pow(4,2) which is 1/16

It looks to me your formula is completely wrong. How you get from (1/9) to (1/25) I don't know, but it doesn't work that that formula or program.

Another point about that equation -- pow(1.0, n+1) -- the result will always be 1 so the formula boils down to 1/pow(n*n,2.0)

>>pow(+1.0, n+1)/pow(n*n,2.0);
How does (1/9) translate to the above equation? When n = 1, the above will be pow(1,2) / pow(1,2) which is 1^2/1^2 = 1. When n = 2, we get pow(1,3)/pow(4,2) which is 1/16

It looks to me your formula is completely wrong. How you get from (1/9) to (1/25) I don't know, but it doesn't work that that formula or program.

Another point about that equation -- pow(1.0, n+1) -- the result will always be 1 so the formula boils down to 1/pow(n*n,2.0)

hi, thanks for your posting...

the solution for the 5series is

for (long int n = 1; n <= i; n++)
{
serieValue+= pow(+1.0, n+1)/pow(n*2,2.0);
}
pi=sqrt(24*serieValue);
n=1 -->> 1*2=2 to the power of 2 = 1/(4)+
n=2 -->> 2*2=4 to the power of 2 = 16 so comes +1/(16)
n=3 --> 3*2=6 to the power of 2 = 26 so coms + 1/(36).
note(do not confused the result of the power with the fraction it's
2 different things...
;) so I confused the 2 series..... i try now on series 4 if i find the anwser i will post it....


for (long int n = 1; n <= i; n++)
{
serieValue+= pow(+1.0, n+1)/pow(n*1,2.0);
n++;
}
pi=sqrt(8*serieValue);

Thank you very much guys for your help....
i fixed my problem.....


here is my code:::

for  (long int j=1,n=1; n,j<=i; j++,n++)
{
if (j>=2)
n++;
serieValue+= pow(+1.0,n-1)/pow(n,2.0)
}
pi=sqrt(8*serieValue);

explaning::if j ==1
pow(+1.0,1-1)/pow( 1,2.0)<=> 1+
if j>=2 (j=2)
pow(+1.0,3-1)/pow(3,2.0<=>1/9+
if j>=2 (j=3)
pow(+1.0,5-1)/pow( 5,2.0)<=>1/25+
if j>=2 (j=4)
pow(+1.0,7-1)/pow( 7,2.0)<=>1/49+

;) Thank you for your help....

what's the point of using pow() in that numerator? 1^N is always 1, so you're just wasting cpu time calculating the value of 1. You would get the same result with this? serieValue+= 1/pow(n,2.0) or this serieValue+= 1/ (n*n) , eliminating the pow() function altogether.

what's the point of using pow() in that numerator? 1^N is always 1, so you're just wasting cpu time calculating the value of 1. You would get the same result with this? serieValue+= 1/pow(n,2.0) or this serieValue+= 1/ (n*n) , eliminating the pow() function altogether.

yeup, you have 100% right, at the begginig of my program i try to find my first problem,

i have error msg for overflow on pow.....because i do this...
serieValue+=pow(1,n)/pow(2*n-1); ( don't ask me why the peoples are differents and they have different mind) :S
pi1=(4*serieValue);
so the power must be 1.0 but i want to know the power n... i mean
on which power the program will be stop......

This question has already been answered. Start a new discussion instead.