60 342
Assignments Done
98%
Successfully Done
In April 2018

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!
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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions