This code is shared by Shweta Jhunjhunwala, thanks for your contribution.
Share your C, C++,C# program with us we will post them here..
C Program to find Sum of Series of Factorial using Recursion
It will give answer of S=(1/1!+2/2!+3/3!+.....n/n!)
Sample Output:
Enter the limit:
5
sum of 1 is 1.000000
sum of 2 is 2.000000
sum of 3 is 2.500000
sum of 4 is 2.666667
sum of 5 is 2.708333
finaly the sum of 5 is 2.708333
Do you wish to Continue(y/n)
Code:
//C Program to find Sum of Series of factorial using recursion
#include<stdio.h>
#include<conio.h>
long int calfact(int x);
void main()
{
int i,x,limit;
float sum=0;
char c;
clrscr();
repeat :
printf("enter the limit:\n");
scanf("%d",&limit);
for(i=1;i<=limit;i++)
{
sum=sum+((float)i/calfact(i));
printf("\nsum of %d is %f\n",i,sum);
}
printf("\nfinally the sum of %d is %f",limit,sum);
fflush(stdin);
printf("\n\nDo you wish to Continue(y/n)");
scanf("%c",&c);
if(c=='y'||c=='Y')
goto repeat;
getch();
}
long int calfact(int x)
{
if(x<=1)
{
return(1);
}
else
{
x=x*calfact(x-1);
return(x);
}
}
Hope you liked the posts, give comments if you have any doubts.. :)#include<stdio.h>
#include<conio.h>
long int calfact(int x);
void main()
{
int i,x,limit;
float sum=0;
char c;
clrscr();
repeat :
printf("enter the limit:\n");
scanf("%d",&limit);
for(i=1;i<=limit;i++)
{
sum=sum+((float)i/calfact(i));
printf("\nsum of %d is %f\n",i,sum);
}
printf("\nfinally the sum of %d is %f",limit,sum);
fflush(stdin);
printf("\n\nDo you wish to Continue(y/n)");
scanf("%c",&c);
if(c=='y'||c=='Y')
goto repeat;
getch();
}
long int calfact(int x)
{
if(x<=1)
{
return(1);
}
else
{
x=x*calfact(x-1);
return(x);
}
}
2 comments:
I didn't get the question itself. I tried a lot to understand the program but can't. Can you explain, what does sum of series of factorial means??
Thanks & Regards,
Yogesh
in the programe sum of series of factorial using recrsion why do we use #include
Post a Comment