Thread: Formula for Pi

  1. #1
    Registered User
    Join Date
    Oct 2003

    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
    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
    An approximation would be 22/7.

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

  5. #5
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    There is this, but in C I might do something like the following.
    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
    Did you try a search on google.

    Here is one link.

  7. #7
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Phildelphia, PA
    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.

    "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
    Groningen (NL)
    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:

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, 04:31 AM
  3. Math formula (js -->C++)
    By Demon1s in forum C++ Programming
    Replies: 20
    Last Post: 05-02-2003, 05:22 AM
  4. Need help with this formula -b/2a..Please read.
    By foofoo in forum C Programming
    Replies: 4
    Last Post: 06-04-2002, 11:59 PM
  5. Formula string conversion
    By Gr3g in forum C++ Programming
    Replies: 2
    Last Post: 04-12-2002, 08:28 PM