Header Ads Widget

C program to generate sum of series 1!+2!+3!+--------------n!

 

 C program to generate sum of series 1!+2!+3!+--------------n! 

Given a number n , write a program to generate a sum of series 1!+2!+3!+--------------n! . For generating this first we have to know that how to find the factorial of a number . 

Program to find the factorial of a number  : -  Click here

Sample input

3

Sample output

Sum of the series is: 9

Explanation:

= 1! + 2! + 3!
=  1+2+6
=  9

C program to generate sum of series 1!+2!+3!+--------------n! 

The objective of the code is to generate sum of series 1!+2!+3!+--------------n!  .

Code(C):-

#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 number\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum=sum+fact(i);
}
printf("Sum of the series is: %d",sum);
return 0;
}

Output:-

Enter a number
3
Sum of the series is: 9


Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-