67 035
Assignments Done
99,3%
Successfully Done
In November 2018

Answer to Question #32317 in C++ for Ankit

Question #32317
Write a function seqsum() in c++ with two arguments, double x and int n. The function should return a value of type double and it should find the sum of the following series:
1+ x/(2!) + x^2/(4!) +........+ x^n/((2n)!)
Expert's answer
#include <iostream>
#include <cmath>


using namespace std;


long factorial(int n)
{
long result = 1;
while (n)
result *= n--;
return result;
}


double seqsum(double x, int n)
{
double result = 1.0;
for (int k = 1; k <= n; k++)
result += pow(x, k) / factorial(2 * k);
return result;
}


int main()
{
cout << "x = 1:" << endl;
for (int n = 0; n < 5; n++)
cout << " n = " << n << " " << seqsum(1, 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