Computer Science, asked by rayyan2878, 6 months ago


2. Write a program to print the sum of the following series?
s={**+1) –**/x+2)) + (**/x+3) – **/x + 4)) +
n terms

Answers

Answered by rakshitha1219
0

Answer:

// C++ implementatio to find

// sum of series of

// 1 + x^2 + x^3 + ....+ x^n

#include <bits/stdc++.h>

using namespace std;

// Function to find the sum of

// the series and print N terms

// of the given series

double sum(int x, int n)

{

double i, total = 1.0, multi = x;

// First Term

cout << total << " ";

// Loop to print the N terms

// of the series and find their sum

for (i = 1; i < n; i++) {

total = total + multi;

cout << multi << " ";

multi = multi * x;

}

cout << "\n";

return total;

}

// Driver code

int main()

{

int x = 2;

int n = 5;

cout << fixed

<< setprecision(2)

<< sum(x, n);

return 0;

}

Similar questions