The mathematician/philosopher Gottfried Wilhelm Leibnitz (1646-1716) derived a calculation to approximate π with the following series expansion formula:
Clearly, the more terms one includes, the closer to the actual value of π the answer becomes. The closeness might look like:
Δ = abs ( ( myPi – π ) / π )
Create a C++ program that asks the user to enter the desired relative tolerance. Then use a function (value-returning or void) called Pi_Whole to perform the calculations. Your program should use a while loop to converge on the solution so that the calculated value of π is within the tolerance to the real thing. The closeness Δ should be a very small number, like 0.00001. Don’t use any more iterations than necessary.
Hint, C++ calls π “M_PI” and it is accessed with the following two C++ statements:
#define _USE_MATH_DEFINES
#include
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here