What is the formula for Pi that I can use in C++?
Printable View
What is the formula for Pi that I can use in C++?
Pi is a constant of 3.1415926535897932384626433832795 which is usually labeled as 3.14. There would be no formula for that.
An approximation would be 22/7.
no..there is definitely a formula.
There is this, but in C I might do something like the following.Code:double pi = 4.0 * atan(1.0);
Did you try a search on google.
Here is one link.
PI
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.
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