Code to determine how many elements of a givine infinite series are required to
find the value of pi, accurate to 5 decimal places?
Sorry the title got cut off. If not the code I'd appreciate a step by step explanation of how to do this problem.
Here it is:
Write a java project (Application) with just a driver class. This class should have a default constructor and a main method which calls it.
This project should determine how many elements of the infinite series shown below are required to find the value of pi, accurate to 5 decimal places.
pi / 4 = 1 - 1 / 3 + 1 / 5 - 1 / 7 + 1 / 9 - 1 / 11 + ...
You must use the following constant
private static final double PI = 3.14159;
and your program must use a do loop.
Your output should look like this:
Value of pi = 3.14159
Number of elements of the series = 130657
The value of pi is not the value of the constant, instead it is the value of the series rounded to 5 places.
Thanks in advance for your time.
Re: Code to determine how many elements of a givine infinite series are required to
First write a bit of code that creates the series 1/1-1/3+1/5-1/7 ... and work from there (the numerator flips between 1 and -1 while the deniminator takes the values 1, 3, 5, 7 ...).
kind regards,
Jos