#include<stdio.h>
#include<conio.h>
void main( )
{
int n,i,j,fact;
float sum=0;
clrscr();
printf("Enter the number of terms:\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact=1;
for(j=i;j>=1;j--) // to find the factorial
fact=fact*j;
sum=sum+(float)i/fact;
}
printf("\nSum : %f",sum);
getch();
}
#include<conio.h>
void main( )
{
int n,i,j,fact;
float sum=0;
clrscr();
printf("Enter the number of terms:\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
fact=1;
for(j=i;j>=1;j--) // to find the factorial
fact=fact*j;
sum=sum+(float)i/fact;
}
printf("\nSum : %f",sum);
getch();
}
No comments:
Post a Comment