Program to find sum of series 1 + 1 / 2 + 1 / 3 + 1 / 4 + . . + 1 / n | C ++ program to find sum of series ; Function to return sum of 1 / 1 + 1 / 2 + 1 / 3 + . . + 1 / n ; Driver code
#include <iostream> NEW_LINE using namespace std ; class gfg { public : double sum ( int n ) { double i , s = 0.0 ; for ( i = 1 ; i <= n ; i ++ ) s = s + 1 / i ; return s ; } } ; int main ( ) { gfg g ; int n = 5 ; cout << " Sum ▁ is ▁ " << g . sum ( n ) ; return 0 ; }