This is a C Program to find sum of the series 1/1! + 2/2! + 3/3! + ……1/N!.
This C Program calculates the Sum of Series 1/1! + 2/2! + 3/3! + ……1/N!.
Take input from the user and calculates the series as shown in the program below.
Here is source code of the C Program to Find the Sum of Series 1/1! + 2/2! + 3/3! + ……1/N!. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/* * C Program to Find find Sum of the Series 1/1! + 2/2! + 3/3! + ……1/N! */ #include <stdio.h> double sumseries(double); main() { double number,sum; printf("\n Enter the value: "); scanf("%lf", &number); sum = sumseries(number); printf("\n Sum of the above series = %lf ", sum); } double sumseries(double m) { double sum2 = 0, f = 1, i; for (i = 1; i <= m; i++) { f = f * i; sum2 = sum2 +(i / f); } return(sum2); }
In this C Program, we are reading the limit using ‘number’ integer variable. The sumseries() function is used to compute the summation of the series by passing the limit ‘number’ variable value as argument.
For loop is used to compute the summation for each integer values in the series up to the limit as mentioned by user in ‘number’ variable. Compute the factorial for the denominator by multiplying the value of ‘f’ variable with the value of ‘i’ variable.
Compute the summation of series by dividing the value of ‘i’ variable by the value of ‘f’ variable. Add the value with the value of ‘sum2’ variable. Print the sum of the series using printf statement.
Output: $ cc pgm20.c $ a.out Enter the value: 5 Sum of the above series = 2.708333
Sanfoundry Global Education & Learning Series – 1000 C Programs.
Here’s the list of Best Books in C Programming, Data-Structures and Algorithms
- Watch Advanced C Programming Videos
- Practice BCA MCQs
- Check Computer Science Books
- Check C Books
- Apply for C Internship