Question: Using C# language to focus on loops and calculations. Write a console application that will calculate the value of PI. (Using the Gregory/Leibniz Convergence Formula

Using C# language to focus on loops and calculations. Write a console application that will calculate the value of PI. (Using the Gregory/Leibniz Convergence Formula for Calculating PI)

In this assignment I need to construct a loop to perform the Leibniz formula at least 1 million times. And because the calculated value of pi will vary based on the number of times we perform this sequence I need to show that the value is at certain intervals of the loop. Specifically, I need to print the calculated value of pi at the following loop intervals:

10 1,000 100,000 500,000 1,000,000

At the end of the loop determined by the value entered by the user. NOT separate loops for each of these outputs. My application has to have a single loop that prints the value of pi at the above given iteration values.

Requirements - The user will be prompted for the number of times the calculation will iterate. - My program needs to validate that the user has entered a valid number and that the number is greater than 1 million. - Using a loop, I need to calculate the value of pi using the Leibniz formula and within the loop show the output value of pi when the loop's index is 10, 1000, 100000, 500000, 1000000, and then again at the end of the loop. (because we want to show the value of pi at the number of iterations specified by the user.) - The loop will end at the count provided by the user when the program started. - In properly formatting output the value of pi must be printed to 10 decimals while the iteration value must include the comma separators. Note: In the example below three values entered were invalid, but the application prevent from ending in an execution error, rather, simply re-prompt the user for a valid entry.

Using C# language to focus on loops and calculations. Write a console

- C:\Users\David AppData\Local\Temporary Projects\ConsoleApp1\bin\Debug ConsoleApp1.exe David's Implementation of the Leibniz Formula: Please enter the number of times to run this calculation Please enter value > 1 million: 2 Please enter value > 1 million: 200 Please enter value > 1 million: foo Please enter value > 1 million: 2000000 At 10 iterations, the value of pi is 3.0418396189 At 1,000 iterations, the value of pi is 3.1405926538 At 100,000 iterations, the value of pi is 3.1415826536 At 500,000 iterations, the value of pi is 3.1415906536 At 1,000,000 iterations, the value of pi is 3.1415916536 At 2,000,000 iterations, the value of pi is 3.1415921536 Please hit Enter key to end

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!