Write a C++ program that calculates the approximated vale of pi (?) using the Gregory-Leibniz series as provided below. Determine it using 20 elements of the series. Display result on screen. $\pi = 4 \sum_{k=0}^{\infty} \frac{(-1)^k}{2k + 1}$
Added by William C.
Close
Step 1
Step 1: We will use a do-while loop to iterate through the series and calculate the value of pi using the Gregory-Leibniz series formula. Show more…
Show all steps
Your feedback will help us improve your experience
Haricharan Gupta and 70 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
linux run
Haricharan G.
run in linux bash
The Wallis Formula is a pattern that calculates the digits of pi! (It is not the best approximation but works fairly well). The more terms included in the calculation, the closer the final value is to the real value of pi. π = 2 * (2*2)/(1*3) * (4*4)/(3*5) * (6*6)/(5*7) * (8*8)/(7*9) .... Ask the user how many terms to use in calculating pi. (A term is one part of the above equation, so 2 is term 1, (2*2)/(1*3) is term 2, etc...) Program Inputs Enter amount of terms to use: - The user will always enter a positive, whole number Program Outputs Pi with XXX terms is YYY - Replace XXX with the amount of terms and YYY with the pi approximation to 8 decimal places Sample Output Test Case 1: Enter amount of terms to use: 2 Pi with 2 terms is 2.66666667 Test Case 2: Enter amount of terms to use: 5 Pi with 5 terms is 2.97215420 Test Case 3: Enter amount of terms to use: 500 Pi with 500 terms is 3.14002068 Test Case 4: Enter amount of terms to use: 100000 Pi with 100000 terms is 3.14158480 Test Case 5: Enter amount of terms to use: 100000000 Pi with 100000000 terms is 3.14159264
Akash M.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD