| > | # A bad Maple program to compute the sum of the harmonic series. |
| > | # We simulate k-digit arithmetic and keep going until the digits stop changing. |
| > | k := 6: # Set number of significant digits.
total := 0: # Initialize the sum. n := 1: # Initialize the index. err := 1: # Initialize the error to something nonzero. while err > 0 do newtotal := evalf[k](total + 1/n): # Keep adding 1/n to the sum and round off to six digits. err := evalf[k](newtotal-total): # Check whether the digits have changed. total := newtotal: # Reset the sum. n := n+1: # Increment the index. end do: print(n,total); # Print results. |