#include<iostream.h>
#include<conio.h>
void main()
{
int n,i;
float sum=1.00;
float fact(int a);
clrscr();
cout<<"Enter n:";
cin>>n;
for(i=1;i<n;i++)
{
sum+=(1/fact(i));
}
cout<<"Sum of series ="<<sum;
getch();
}
float fact (int a)
{
int f=1,i;
for (i=1;i<=a;i++)
f*=i;
return f;
}
OUTPUT:
Enter n : 5
Sum of series =2.708333
No comments:
Post a Comment