Program to find the Nth Harmonic Number | CPP 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
#include <iostream> NEW_LINE using namespace std ; double nthHarmonic ( int N ) { float harmonic = 1.00 ; for ( int i = 2 ; i <= N ; i ++ ) { harmonic += ( float ) 1 / i ; } return harmonic ; } int main ( ) { int N = 8 ; cout << nthHarmonic ( N ) ; return 0 ; }