Write a program to calculate the sum of the following series:
1/1!+2/2!+3/3!+4/4!+5/5!+6/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/1!+2/2!+3/3!+4/4!+5/5!+ - - - - - - \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;j++)
{
fact=fact*j;
}
term=i/fact;
sum=sum+term;
}
cout << "Sum is: "<< sum << endl;
cout <<endl;
return 0;
}
}
No comments:
Post a Comment