# need help with series-- please

Printable View

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 09-22-2007
cs1
need help with series-- please
hey guys i need ur help to do this question please

Calculate the value of pi = 4- 4/3+ 4/5 – 4/7 + 4/9 – 4/11 + ……………..

Print a table that shows the approximate value of pi after each of the first 20 terms of this series.

thanks

i dont want the answer but i want to know how to do it.
• 09-22-2007
Salem
I would suggest using a for loop.
• 09-22-2007
ggs
Ignore the man before me. The while loop is superior in every way.
• 09-22-2007
cs1
thank u salem
i know that i have to use for loop
my problem is how????????????????

thanks again
• 09-22-2007
cs1
thanks ggs
but now i need to know it's work
i mean how can i do my program
thanks again
• 09-22-2007
Salem
Well you want 20 terms, so how about
for ( nTerms = 0 ; nTerms < 20 ; nTerms++ )

Don't think we're being mean or anything, but it's hard to describe what is basically 1 line of code without giving the whole game away.

Post an effort of your own.
• 09-22-2007
swgh
Quote:

Originally Posted by ggs
Ignore the man before me. The while loop is superior in every way.

Considering the for loop is a while loop condensed into one statement what you said doesnt really make any sense. And Salem is a very seasoned proffesional so he was is correct 99% of the time. Although either loop would work well.
• 09-22-2007
cs1
thank u all
here what i did

pi=pi = 4- 4/3+ 4/5 – 4/7 + 4/9 – 4/11 + …………….
i= 3,5,7,9,11,................
for (i=3; i < 20; i = i + 2)
j=0
pi=4
if (j&#37;2==0)
pi= pi - 4. /i;
else pi= pi+4. /i;
cout <<pi<<endl;

please let me know if what i did is correct or not
• 09-22-2007
hk_mp5kpdw
The first term is 4 (or 4/1).
The second term is -4/3.
The third term is 4/5.
The fourth term is -4/7.

Do you see what is happening? The denominator increases by 2 every term and the sign flips every term. The sign flip can be done with a multiplication of -1 and the other, well... if you don't know how to add 2 to something you're in the wrong business. The rest is straight addition of those terms.
• 09-22-2007
cs1
thanks hk_mp5kpdw
but if u would explain to me more that will be helpful
please
• 09-22-2007
CodeMonkey
Now now. "Explain to me more." Consider what it is you are having trouble understanding (this might take some thought, maybe a snack or a quick nap), and then ask a question. Use messages to contact board members, not posts.
• 09-22-2007
cs1
CodeMonkey
do u know how to do it????
• 09-22-2007
CodeMonkey
Anyone who read hk's post knows how to do it. Except you.
• 09-22-2007
cs1
so what do u want now
is there any problem if i want to learn how to do it?
people are diffreent.

if u dont want to help please dont bother yourself with my problem
• 09-22-2007
cs1
and i'm sure u dont know how to do it ;)
Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last