program in C++ to find the sum of the series [ x - x^3 + x^5 + ......].

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


Test Data : 
Input the value of x :2 
Input number of terms : 5
Expected Output :
The sum = 0.909347 
Number of terms = 5 
The value of x = 2.000000 

program in C++ to find the sum of the series [ x - x^3 + x^5 + ......]. program in C++ to find the sum of the series [ x - x^3 + x^5 + ......]. Reviewed by Unknown on May 21, 2017 Rating: 5

No comments:

Powered by Blogger.