C Program to Find Sum of the Series 1/1! + 2/2! + 3/3! + ……1/N!

This is a C Program to find sum of the series 1/1! + 2/2! + 3/3! + ……1/N!.

Problem Description

This C Program calculates the Sum of Series 1/1! + 2/2! + 3/3! + ……1/N!.

Problem Solution

Take input from the user and calculates the series as shown in the program below.

Program/Source Code

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);
}
Program Explanation

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.

advertisement
advertisement

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.

Runtime Test Cases
 
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.

Note: Join free Sanfoundry classes at Telegram or Youtube

Here’s the list of Best Books in C Programming, Data-Structures and Algorithms

If you wish to look at other example programs on Mathematical Functions, go to C Programming Examples on Mathematical Functions. If you wish to look at programming examples on all topics, go to C Programming Examples.

advertisement
If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.