Programming for Problem Solving

GTU Practical 27

27. Write a C program to find 1+1/2!+1/3!+1/4!+…..+1/n!.
#include<stdio.h>  ( this applies in the given code )

#include

int main()
{
int n,i,j,fact=1;
float sum=0;
printf(“\n Enter Value of n : “);
scanf(“%d”,&n);
for(i=1;i0;j–)
{
fact=fact * j;
}
sum=sum+(1.0/fact);
}
printf(“\n Sum of Series = %f”,sum);
return 0;
}

OUTPUT

Enter Value of n : 6

Sum of Series = 1.718055

GTU STUDY