Lesson goal: Adding numbers to find Pi

Previous: Adding numbers like Carl Gauss did | Home | Next: Finding square roots

The famous number $\pi=3.1415...$ can be found by adding together certain patterns of numbers. There are many such patterns, and we'll use one of them here. When finding $\pi$ in this manner, the more numbers you add the better your result for $\pi$ will be. This is called the "infinite series" approach to finding $\pi$.

The infinite series we'll use for $\pi$ is this one $\frac{\pi^2}{6}=\frac{1}{1^2}+\frac{1}{2^2}+\frac{1}{3^2}+\frac{1}{4^2}+...$. As you can see, there is a definite pattern on the right side. Just count from $1$ to $2$ to $3$, etc., always putting the count number (squared) into the denominator of a fraction, with $1$ as the numerator. If you keep adding these fractions, you'll get $\pi^2/6$.

Now you try. Use a for loop and a separate variable called sum to add up ten terms of the $\pi$ sum shown above.

Type your code here:

See your results here: