Program to find the Nth Harmonic Number | C # program to find N - th 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
using System ; class GFG { static double nthHarmonic ( int N ) { float harmonic = 1 ; for ( int i = 2 ; i <= N ; i ++ ) { harmonic += ( float ) 1 / i ; } return harmonic ; } static public void Main ( ) { int N = 8 ; Console . Write ( nthHarmonic ( N ) ) ; } }