# Answer to Question #25725 in C++ for jakshil gandhi

Question #25725

Write a function in C ++ having 2 parameters x and n of integer type with result

type float to find the sum of following series :-

1 + x/2! + x2/ 3! +…………………..+xn/n+1!

type float to find the sum of following series :-

1 + x/2! + x2/ 3! +…………………..+xn/n+1!

Expert's answer

#include <iostream>

#include <cmath>

using namespace std;

long factorial(int n)

{

long result = 1;

while (n-- > 1)

result *= n;

return result;

}

double series(int x, int n)

{

double result = 1;

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

result += pow(x, i) / factorial(i);

return result;

}

int main()

{

int x = 3;

int n = 10;

cout << "x = 3, n = 10" << endl;

cout << "Series sum: " << series(x, n) << endl;

return 0;

}

#include <cmath>

using namespace std;

long factorial(int n)

{

long result = 1;

while (n-- > 1)

result *= n;

return result;

}

double series(int x, int n)

{

double result = 1;

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

result += pow(x, i) / factorial(i);

return result;

}

int main()

{

int x = 3;

int n = 10;

cout << "x = 3, n = 10" << endl;

cout << "Series sum: " << series(x, n) << endl;

return 0;

}

## Comments

## Leave a comment