Question: Write a C++ program that approximates the value of the constant , based on both the Leibniz and the Wallis formulas for estimating . The

Write a C++ program that approximates the value of the constant , based on both the Leibniz and the Wallis formulas for estimating . The formulas are shown in the images below:

Write a C++ program that approximates the value of the constant ,

based on both the Leibniz and the Wallis formulas for estimating .

The formulas work well for high values of n.

The program takes an input from the user for the value of n, which determines the number of terms in the approximation of the value of pi. The program then outputs that calculation for both formulas. You must also include a loop that allows the user to repeat this calculation for new values n until the user says she or he wants to end the program by issuing an input of 0. The results must be shown to the 5th decimal place.

The program should print a string of text to the terminal before getting each piece of input from the user. A session should look like the following example (including whitespace and formatting), with various and different inputs and numbers in the output:

Enter the number of terms to approximate (or zero to quit): 5 The approximation for Leibniz's Formula is 2.97605 using 5 terms. The approximation for Wallis' Formula is 3.00218 using 5 terms. Enter the number of terms to approximate (or zero to quit): 50 The approximation for Leibniz's Formula is 3.16120 using 50 terms. The approximation for Wallis' Formula is 3.12608 using 50 terms. Enter the number of terms to approximate (or zero to quit): 1000 The approximation for Leibniz's Formula is 3.14259 using 1000 terms. The approximation for Wallis' Formula is 3.14081 using 1000 terms. Enter the number of terms to approximate (or zero to quit): 0 

Note that each string printed by the program should include a newline at the end, but no other trailing whitespace (whitespace at the end of the line). Note that when the program exits, when a user enters 0, there is a newline generated.

2 1 5 3 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!