Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that approximates the sum of this geometric series using a user-

ID: 3834809 • Letter: W

Question

Write a program that approximates the sum of this geometric series using a user- specified number of terms. For example, if you named your program approx, calling approx(3) should use the first 3 terms of the series to calculate the approximation:

Approximate result = 1/2 + 1/4 + 1/8 = 0.875...
Note: the values are all powers of 12: (1/2)1, (1/2)2, (1/2)3, ...

Next, have your program calculate the difference (rounded to 3 decimal places) between the value “1” and the approximation calculated by your program:

Difference = 1 – approximate result = 0.125

HINT: You will probably want to define some variables before your for loop, such as a variable to keep track of the value of the current term and a variable to keep track of the sign of the current term. For example, initially, you can have approx = 0. As the program iterates through the loop, approx can be modified using approx = approx + current.

(NOTE: Make sure your program is not doing integer division (see p. 59). If you are using a version of Python earlier than Python 3, the division operator “/” may not give you the result you are expecting.)

You may have noticed that the approximation, at least using just 3 terms, is not very accurate. Modify your program from part a to look at all how the approximation improves as more terms are used. Your modified program will NOT do the comparison to 1 – it will just print out the value of the current approximation. For example, if you name your modified program approx2, calling approx2(3) will print out the following:

0.5 0.75 0.875

Now have your modified program round responses to 2 decimal places. How many terms are needed for the approximation to return a result of 0.99 or greater?

Explanation / Answer

#include double f(double x); int main() { unsigned int start = 1; unsigned int end = 1000; double sum = 0; for( unsigned int x = start; x
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote