Friday 23 November 2012

Code to calculate the sum of series 1/2!+2/3!+3/4!+4/5!+5/6!+ - - - - - -



#include <iostream>
using namespace std;
int main()
{
double fact,term,sum=0;
int length;
cout << "This program will disply the sum of following series... \n"<<endl;
cout << "1/2!+2/3!+3/4!+4/5!+5/6!+ - - - - - - \n"<<endl;
cout << "Enter Length of the series: ";
cin >> length;
for (int i=1;i<=length;i++)
{
fact=1;
for (int j=1;j<=i+1;j++)
{
fact=fact*j;
}
term=i/fact;
sum=sum+term;
}
cout << "Sum is: "<< sum << endl;
cout <<endl;

return 0;
}

No comments:

Post a Comment