Get Answers to all your Questions

header-bg qa

I need a c++ program to print the sum of series, 2 +(2+4) +(2+4+6) +........+ nth term.N to be obtained from the user.

Answers (1)

best_answer

// C++ implementation to find the sum 
// of the given series 
#include <bits/stdc++.h> 

using namespace std; 

// function to find the sum 
// of the given series 
int sumOfTheSeries(int n) 
 
    int sum = 0; 
    for (int i = 1; i <= n; i++)  

        // first term of each i-th term 
        int k = 2; 
        for (int j = 1; j <= i; j++)  
            sum += k; 

            // next term 
            k += 2; 
         
     

    // required sum 
    return sum; 
 

// Driver program to test above 
int main() 
 
    int n = 5; 
    cout << "Sum = "
        << sumOfTheSeries(n); 
    return 0; 
 
 

Posted by

Deependra Verma

View full answer