Program to find the Nth Harmonic Number | Function to find N - th Harmonic Number ; H1 = 1 ; loop to apply the forumula Hn = H1 + H2 + H3 ... + Hn - 1 + Hn - 1 + 1 / n ; Driver Code
function nthHarmonic ( N ) { let harmonic = 1.00 ; for ( let i = 2 ; i <= N ; i ++ ) { harmonic += parseFloat ( 1 ) / i ; } return harmonic ; } let N = 8 ; document . write ( nthHarmonic ( N ) . toFixed ( 5 ) ) ;