What the program needs to do is to find the sum of all the terms in a series. Since the series is infinite, then realistically it must just include some chosen number of terms from the start of the series, and ignore the rest.
From the image file, we see this:
PI = 4 * (1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + 1/13 -1/15 + 1/17 - 1/19 + ....) |
What does this mean? Well, first get the total of the series in brackets, and the last thing to do is to multiply that by 4. So already we know what the last line of code is (before the output).
The series itself follows a straightforward pattern. The sign alternates between plus and minus, so we must add the first term, subtract the second and so on.
Each term is just a simple fraction, the numerator is always 1, the denominator is just the series of odd numbers starting from 1.
Now you see how it is constructed, getting the program working should be fairly simple.