Formula for Pi

This is a discussion on Formula for Pi within the C++ Programming forums, part of the General Programming Boards category; What is the formula for Pi that I can use in C++?...

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    14

    Formula for Pi

    What is the formula for Pi that I can use in C++?

  2. #2
    Master of the Universe! velius's Avatar
    Join Date
    Sep 2003
    Posts
    219
    Pi is a constant of 3.1415926535897932384626433832795 which is usually labeled as 3.14. There would be no formula for that.
    While you're breakin' down my back n'
    I been rackin' out my brain
    It don't matter how we make it
    'Cause it always ends the same
    You can push it for more mileage
    But your flaps r' wearin' thin
    And I could sleep on it 'til mornin'
    But this nightmare never ends
    Don't forget to call my lawyers
    With ridiculous demands
    An you can take the pity so far
    But it's more than I can stand
    'Cause this couchtrip's gettin' older
    Tell me how long has it been
    'Cause 5 years is forever
    An you haven't grown up yet
    -- You Could Be Mine - Guns N' Roses

  3. #3
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    An approximation would be 22/7.

  4. #4
    Registered User
    Join Date
    Oct 2003
    Posts
    14
    no..there is definitely a formula.

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    There is this, but in C I might do something like the following.
    Code:
    double pi = 4.0 * atan(1.0);
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  6. #6
    Registered User
    Join Date
    Jul 2003
    Posts
    450
    Did you try a search on google.

    Here is one link.
    PI

  7. #7
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    There are plenty of ways to calculate Pi. When you get to Calc 3, you'll learn about series and use them to find approximations for Pi and e. If you just need to use Pi in a program, declare PI as a constant that has as many decimal places as you want of accuracy.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  8. #8
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    There are many ways to calculate pi. Note that if you want to calculate pi during the running of your program, this may be very inefficient. Better would be to store pi as a constant and use that constant. Ofcourse you'll always work with approximations of pi.

    Here are some links on calculating pi:
    http://mathworld.wolfram.com/PiApproximations.html
    http://mathworld.wolfram.com/PiFormulas.html
    http://www.myownlittleworld.com/pi/links.html

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Zeller's Formula
    By unejam2005 in forum C++ Programming
    Replies: 6
    Last Post: 11-14-2005, 09:48 PM
  2. how to change char to formula
    By kosong in forum C Programming
    Replies: 2
    Last Post: 06-09-2003, 05:31 AM
  3. Math formula (js -->C++)
    By Demon1s in forum C++ Programming
    Replies: 20
    Last Post: 05-02-2003, 06:22 AM
  4. Need help with this formula -b/2a..Please read.
    By foofoo in forum C Programming
    Replies: 4
    Last Post: 06-05-2002, 12:59 AM
  5. Formula string conversion
    By Gr3g in forum C++ Programming
    Replies: 2
    Last Post: 04-12-2002, 09:28 PM

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