C programming problems
Algorithm and data structure
Sunday, December 21, 2014
Efficient Program to Compute Sum of Series 1/1! + 1/2! + 1/3! + 1/4! + .. + 1/n!
#include<stdio.h>
int main()
{
int fact[10];
int i,n;
float sum=0;
fact[1]=fact[0]=1;
printf("Enter value");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact[i]=fact[i-1]*i;
sum+=(float)1/fact[i];
}
printf("%f",sum);
return 0;
}
Newer Post
Older Post
Home