next up previous
Next: What to turn in Up: Assignment 5: Moiré patterns Previous: Draw a radial Moiré

And now for something completely different...

This part of the assignment is from the book, page 184.

1.
Create a new project named Loop, and make it an Application.
2.
Evaluate the expression

\begin{displaymath}
\sum_{i=1}^{10,000} \frac{1}{i}\end{displaymath} (1)

with two different for loops; first use

for (int i = 1; i <= 10000; i++)

and then use

for (int i = 10000; i >= 1; i--)

3.
Explain why the printed values are not equal. What is the more accurate value?

4.
If you do not understand what is happening, try doing the computation on paper, adding only the first ten values, and using two-digit decimal math. In other words, round everything off to two significant digits at each step of the calculation. For example, 1 + 1/2 + 1/3 = 1.0 + 0.5 + .33 = 1.8



Allen B. Downey
3/3/1998