Program to find sum of harmonic series | C ++ program to find sum of harmonic series ; Function to return sum of harmonic series ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; double sum ( int n ) { double i , s = 0.0 ; for ( i = 1 ; i <= n ; i ++ ) s = s + 1 / i ; return s ; } int main ( ) { int n = 5 ; cout << " Sum ▁ is ▁ " << sum ( n ) ; return 0 ; }