need help with series-- please

This is a discussion on need help with series-- please within the C++ Programming forums, part of the General Programming Boards category; hey guys i need ur help to do this question please Calculate the value of pi = 4- 4/3+ 4/5 ...

  1. #1
    cs1
    cs1 is offline
    Registered User
    Join Date
    Sep 2007
    Posts
    9

    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.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    I would suggest using a for loop.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    ggs
    ggs is offline
    C > C++ duders ggs's Avatar
    Join Date
    Aug 2001
    Posts
    435
    Ignore the man before me. The while loop is superior in every way.
    .sect signature

  4. #4
    cs1
    cs1 is offline
    Registered User
    Join Date
    Sep 2007
    Posts
    9
    thank u salem
    i know that i have to use for loop
    my problem is how????????????????

    thanks again

  5. #5
    cs1
    cs1 is offline
    Registered User
    Join Date
    Sep 2007
    Posts
    9
    thanks ggs
    but now i need to know it's work
    i mean how can i do my program
    thanks again

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475
    Quote Originally Posted by ggs View Post
    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.
    I'm just trying to be a better person - My Name Is Earl

  8. #8
    cs1
    cs1 is offline
    Registered User
    Join Date
    Sep 2007
    Posts
    9
    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

  9. #9
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,798
    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.
    Last edited by hk_mp5kpdw; 09-22-2007 at 09:30 PM. Reason: third <> fourth
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  10. #10
    cs1
    cs1 is offline
    Registered User
    Join Date
    Sep 2007
    Posts
    9
    thanks hk_mp5kpdw
    but if u would explain to me more that will be helpful
    please

  11. #11
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    902
    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.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  12. #12
    cs1
    cs1 is offline
    Registered User
    Join Date
    Sep 2007
    Posts
    9
    CodeMonkey
    do u know how to do it????

  13. #13
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    902
    Anyone who read hk's post knows how to do it. Except you.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  14. #14
    cs1
    cs1 is offline
    Registered User
    Join Date
    Sep 2007
    Posts
    9
    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

  15. #15
    cs1
    cs1 is offline
    Registered User
    Join Date
    Sep 2007
    Posts
    9
    and i'm sure u dont know how to do it
    Last edited by cs1; 09-22-2007 at 11:27 PM.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sine series summation
    By kashya in forum C Programming
    Replies: 3
    Last Post: 12-17-2008, 07:00 PM
  2. Cosine - Maclaurin Series
    By carrotcake1029 in forum C Programming
    Replies: 12
    Last Post: 12-07-2008, 11:20 AM
  3. Implement of a Fast Time Series Evaluation Algorithm
    By BiGreat in forum C Programming
    Replies: 7
    Last Post: 12-04-2007, 01:30 AM
  4. Problem with implementing Liebniz series
    By C_Necessity in forum C Programming
    Replies: 6
    Last Post: 06-15-2005, 12:39 PM
  5. array of series
    By ronenk in forum C Programming
    Replies: 11
    Last Post: 06-22-2004, 01:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21