Write a program to generate sum of series 1!+2!+3!+--------------n!
In order generate sum of series 1!+2!+3!+--------------n! there is need to take help of function that can able to calculate the factorial of any number
Program in C language
#include<stdio.h>
#include<conio.h>
int fact(int n)
{
if(n==1)
return 1;
else
return n*fact(n-1);
}
void main()
{
int n,factorial,sum=0,i;
printf("enter a number \n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
factorial=fact(i);
sum=sum+factorial;
}
printf("Sum of the given series is %d",sum);
getch();
}
No comments:
Post a Comment