# Answer to Question #74793 in C++ for Dillon Morris

Question #74793

a. The sum of a series can be computed as sum=x+x^2/2+x^3/3+x^4/4+x^5/5+⋯ ∞<x<∞ stopping when either n terms have been added or when the magnitude of a term in the series is less than 10-6, whichever comes first.

You are required to write a function, sumSeries, which given x, n returns the sum of the series. Use #include <cmath> and the abs function. Do not use the pow function.

You are required to write a function, sumSeries, which given x, n returns the sum of the series. Use #include <cmath> and the abs function. Do not use the pow function.

Expert's answer

#include <cmath>

double sumSeries(double x, int n)

{

double sum = 0;

double nominator = 1;

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

{

nominator *= x;

double element = nominator/i;

sum += element;

if (std::abs(element) < 0.00001)

break;

}

return sum;

}

double sumSeries(double x, int n)

{

double sum = 0;

double nominator = 1;

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

{

nominator *= x;

double element = nominator/i;

sum += element;

if (std::abs(element) < 0.00001)

break;

}

return sum;

}

Need a fast expert's response?

Submit orderand get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

## Comments

## Leave a comment