Program to find sum of series 1 + 1 / 2 + 1 / 3 + 1 / 4 + . . + 1 / n | Function to return sum of 1 / 1 + 1 / 2 + 1 / 3 + . . + 1 / n ; Driven Program
function sum ( n ) { var i , s = 0.0 ; for ( i = 1 ; i <= n ; i ++ ) s = s + 1 / i ; return s ; } var n = 5 ; document . write ( sum ( n ) . toFixed ( 5 ) ) ;