Question #32717

write a program to find the sum of following series:-

1+x/1!+x^3/2!+x^5/3!+............+x^(2n-1)/n!

1+x/1!+x^3/2!+x^5/3!+............+x^(2n-1)/n!

Expert's answer

#include <iostream>

#include <conio.h>

using namespace std;

double factorial(long n){

if (n < 1)

return 0;

double product = 1;

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

product *= i;

return product;

}

//main function

int main()

{

double x;

double sum=1;

cout<<"Enter x = ";//input x

cin>>x;//read x

//calculate sum

for(int n=1;n<10;n++){

sum+=pow(x,(2*n-1))/factorial(n);

}

//show result

cout<<"Sum="<<sum;

getch();//delay

return 0;

}

#include <conio.h>

using namespace std;

double factorial(long n){

if (n < 1)

return 0;

double product = 1;

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

product *= i;

return product;

}

//main function

int main()

{

double x;

double sum=1;

cout<<"Enter x = ";//input x

cin>>x;//read x

//calculate sum

for(int n=1;n<10;n++){

sum+=pow(x,(2*n-1))/factorial(n);

}

//show result

cout<<"Sum="<<sum;

getch();//delay

return 0;

}

## Comments

## Leave a comment