Write a program to generate sum of series 1!+2!+3!+————–n!

 Code:-


#include<stdio.h>

// function for finding factorial
int fact(int n)
{
int i,f=1;
for(i=1;i<=n;i++)
f=f*i;
return f;
}
int main()
{
int n,sum=0,i;
printf(“Enter a numbern”);
scanf(“%d”,&n);
for(i=1;i<=n;i++)
{
sum=sum+fact(i);
}
printf(“Sum of the series is: %d”,sum);
return 0;
}

Ouput:-

Enter a number
3
Sum of the series is: 9

Recommended Post:

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

Key points:-

 MCQs:-





Leave a Reply

Your email address will not be published.