View My Stats

Total Pageviews

Saturday 16 March 2013

sum to series of n terms


//fnd the sum of1+1/1!+1/2!..........+1/n!;
#include<iostream.h>
void main()
{
float t,sum;
int n,i;
cout<<"enter the value of n"<<endl;
cin>>n;
t=t+1;
t=1;
sum=1;
for(i=1;i<=n;i++)
{
while(n)
{
t=t*1/n;
--n;
}
sum+=t;
}
cout<<sum;
}

No comments:

Post a Comment