Write a program in C++ to find the sum of the series [ 1-X^2/2!+X^4/4!- .........]. .


#include <iostream>
using namespace std;
void main()
{
  float x,sum,t,d;
int i,n;
cout<<"Input the Value of x :";
cin>>x;
cout<<"Input the number of terms : ";
cin>>n;
sum =1; t = 1;
for (i=1;i<n;i++)
{
 d = (2*i)*(2*i-1);
 t = -t*x*x/d;
 sum =sum+ t;
}
cout<<"\nthe sum = "<<sum<<"\nNumber of terms = "<<n<<"\nvalue of x = "<<x<<endl;
       system ("pause");
}


Test Data :
Input the Value of x :2
Input the number of terms : 5
Expected Output :
the sum = -0.415873
Number of terms = 5
value of x = 2.000000
Write a program in C++ to find the sum of the series [ 1-X^2/2!+X^4/4!- .........]. . Write a program in C++ to find the sum of the series [ 1-X^2/2!+X^4/4!- .........]. . Reviewed by Unknown on May 18, 2017 Rating: 5

No comments:

Powered by Blogger.