Program to find the sum of the series 1 + x + x ^ 2 + x ^ 3 + . . + x ^ n | C ++ implementation to find sum of series of 1 + x ^ 2 + x ^ 3 + ... . + x ^ n ; Function to find the sum of the series and print N terms of the given series ; First Term ; Loop to print the N terms of the series and find their sum ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; double sum ( int x , int n ) { double i , total = 1.0 , multi = x ; cout << total << " ▁ " ; for ( i = 1 ; i < n ; i ++ ) { total = total + multi ; cout << multi << " ▁ " ; multi = multi * x ; } cout << " STRNEWLINE " ; return total ; } int main ( ) { int x = 2 ; int n = 5 ; cout << fixed << setprecision ( 2 ) << sum ( x , n ) ; return 0 ; }