program in C++ to display the sum of the series [ 1+x+x^2/2!+x^3/3!+....]

#include <iostream>
using namespace std;
void main()
{
float x,sum,no_row;
int i,n;
cout<<"Input the value of x :";
cin>>x;
cout<<"Input number of terms : ";
cin>>n;
sum =1; no_row = 1;
for (i=1;i<n;i++)
{
 no_row = no_row*x/(float)i;
 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 :3 
Input number of terms : 5 
Expected Output :
The sum is : 16.375000 
Number of terms = 5 
The value of x = 3.000000

program in C++ to display the sum of the series [ 1+x+x^2/2!+x^3/3!+....] program in C++ to display the sum of the series [ 1+x+x^2/2!+x^3/3!+....] Reviewed by Unknown on May 21, 2017 Rating: 5

No comments:

Powered by Blogger.