Find the sum of the series x ( x + y ) + x ^ 2 ( x ^ 2 + y ^ 2 ) + x ^ 3 ( x ^ 3 + y ^ 3 ) + ... + x ^ n ( x ^ n + y ^ n ) | CPP program to find the sum of series ; Function to return required sum ; sum of first series ; sum of second series ; Driver Code ; function call to print sum
#include <bits/stdc++.h> NEW_LINE using namespace std ; int sum ( int x , int y , int n ) { int sum1 = ( pow ( x , 2 ) * ( pow ( x , 2 * n ) - 1 ) ) / ( pow ( x , 2 ) - 1 ) ; int sum2 = ( x * y * ( pow ( x , n ) * pow ( y , n ) - 1 ) ) / ( x * y - 1 ) ; return sum1 + sum2 ; } int main ( ) { int x = 2 , y = 2 , n = 2 ; cout << sum ( x , y , n ) ; return 0 ; }