/* This program find sum of series 1!+2!+3!+4!+……..+n! without using function */

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include<stdio.h> int main() { int num,i,j,fact,sum=0;//variables printf("Enter the last number of series:\n"); scanf("%d",&num);//last number of series for(i=1;i<=num;i++)//loop for finding factorial and sum { fact=1; if(i!=num) printf("%d!+ ",i); else printf("%d!= ",i); for(j=1;j<=i;j++) fact=fact*j; sum=sum+fact; } printf("%d",sum); return 0; } |

Note: Program Compiled in Dev C++ compiler.

**OUTPUT:**

1 2 3 |
Enter the last number of series: 10 1!+ 2!+ 3!+ 4!+ 5!+ 6!+ 7!+ 8!+ 9!+ 10!= 4037913 |

**Description:**

- Variable num is used for the storing last element of the series. i & j are used for iteration purpose in loop.fact is used for finding the factorial of each element. Finally sum will store the sum of series 1!+2!+3!+4!+……..+n!.
- Here two for loops are used. First loop is used for iteration so that each element can be traversed.
- Another loop is used for finding the factorial of each loop.Finally after calculating factorial of element it is added to sum.
- Finally factorial of element is added with sum.

## “Program to find sum of series 1!+2!+3!+4!+……..+n! using function.”

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
#include<stdio.h> int add(int num) { int i,j,fact,sum=0; for(i=1;i<=num;i++)//loop for finding factorial and sum { fact=1; if(i!=num) printf("%d!+ ",i); else printf("%d!= ",i); for(j=1;j<=i;j++) fact=fact*j; sum=sum+fact; } return sum; } int main() { int num; printf("Enter the last number of series:\n"); scanf("%d",&num);//last number of series printf("%d",add(num)); return 0; } |

**OUTPUT:**

1 2 3 |
Enter the last number of series: 10 1!+ 2!+ 3!+ 4!+ 5!+ 6!+ 7!+ 8!+ 9!+ 10!= 4037913 |

Finally you also learned how to find sum using function.So I hope you can solve related programs.

### Free online test powered by Quick Solution.

### C programming Videos by Quick Solution.

### Click here to go program gallery.