Sum of the Series 1 + x / 1 + x ^ 2 / 2 + x ^ 3 / 3 + . . + x ^ n / n | C ++ program to find sum of series 1 + x / 1 + x ^ 2 / 2 + x ^ 3 / 3 + ... . + x ^ n / n ; Funciton to print the sum of the series ; Driver code
#include <math.h> NEW_LINE #include <iostream> NEW_LINE #include <boost/format.hpp> NEW_LINE class gfg { public : double sum ( int x , int n ) { double i , total = 1.0 ; for ( i = 1 ; i <= n ; i ++ ) total = total + ( pow ( x , i ) / i ) ; return total ; } } ; int main ( ) { gfg g ; int x = 2 ; int n = 5 ; std :: cout << boost :: format ( " % .2f " ) % g . sum ( x , n ) ; return 0 ; }