

 This page uses content from Wikipedia. The original article was at Harmonic number. The list of authors can be seen in the page history. As with Rosetta Code, the text of Wikipedia is available under the GNU FDL. (See links for details on variance)



In mathematics, the n-th harmonic number is the sum of the reciprocals of the first n natural numbers:

   Hn = 1 + 1/2 + 1/3 + ... + 1/n

The series of harmonic numbers thus obtained is often loosely referred to as the harmonic series.

Harmonic numbers are closely related to the Riemann zeta function, and roughly approximate the natural logarithm function; differing by γ (lowercase Gamma), the Euler–Mascheroni constant.

The harmonic series is divergent, albeit quite slowly, and grows toward infinity.



Task
 Write a function (routine, procedure, whatever it may be called in your language) to generate harmonic numbers.
 Use that procedure to show the values of the first 20 harmonic numbers.
 Find and show the position in the series of the first value greater than the integers 1 through 5


Stretch
 Find and show the position in the series of the first value greater than the integers 6 through 10


Related
 Egyptian fractions


 
decimals(12)
sum = 0
nNew = 1
limit = 13000
Harmonic = []
 
 
for n = 1 to limit
    sum += 1/n
    add(Harmonic,[n,sum])
next
 
see "The first twenty harmonic numbers are:" + nl
for n = 1 to 20
    see "" + Harmonic[n][1] + " -> " + Harmonic[n][2] + nl
next
see nl
 
for m = 1 to 10
    for n = nNew to len(Harmonic)
        if Harmonic[n][2] > m
           see "The first harmonic number greater than "
           see "" + m + " is " + Harmonic[n][2] + ", at position " + n + nl
           nNew = n
           exit
        ok
    next
next
 