Wednesday, October 5, 2011

Sum of a given series






Write a program to compute the sum of the following series:

(1/1!)+(2/2!)+(3/3!)+..........................+(n/n!)




Program...

#include<stdio.h>
#include<conio.h>
float factorial(int n);
void main()
{
int l,i;
float sum=0.0;
clrscr();
printf("Enter the limit :\n");
scanf("%d",&l);
for(i=1;i<=l;i++)
{
sum=sum+(i/factorial(i));
}
printf("the sum of the series is:%f",sum);
getch();
}

float factorial(int n)
{
int fact=1,i;
for(i=1;i<=n;i++)
fact=fact*i;
return fact;
}


Output...


0 comments:

Post a Comment

About Me