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

Introduction

This article will help you write a C program to find the sum of the series 1 + 1/2! + 1/3! + … + 1/n!.
This series is known as the exponential series and is commonly used in mathematics and science, especially in approximating the value of e (Euler’s number).


Problem Statement

Given an integer value n, calculate the sum:
1 + 1/2! + 1/3! + 1/4! + … + 1/n!

This series involves computing factorial values in the denominator and summing their reciprocals.


C Program to Calculate the Series

#include <stdio.h>

int main() {
int i, j, n, fact;
float sum = 1.0;

printf("Enter the value of n: ");
scanf("%d", &n);

for(i = 2; i <= n; i++) {
fact = 1;
for(j = 1; j <= i; j++) {
fact *= j;
}
sum += 1.0 / fact;
}

printf("Sum of the series 1 + 1/2! + ... + 1/%d! is: %.4f\n", n, sum);
return 0;
}

Explanation

  • Input: User enters n
  • Outer Loop: Runs from 2 to n to calculate each factorial
  • Inner Loop: Calculates factorial of i
  • Sum: Adds 1/fact to the total
  • Output: The final result is shown with 4 decimal precision

Sample Output

Enter the value of n: 5  
Sum of the series 1 + 1/2! + 1/3! + 1/4! + 1/5! is: 1.7167

Why Use This Series

  • Helps understand nested loops
  • Common in mathematics and scientific computing
  • Used to approximate e (Euler’s constant)
  • Excellent practice problem for factorial and floating-point logic

Conclusion

This C program factorial series example is a great way to practice loop nesting and precision handling in C. It helps you understand how factorials work and how to use them in real mathematical series.

Previous Article

C Program to Find the Sum of Harmonic Series 1 + 1/2 + 1/3 + … + 1/n

Next Article

C Program to Evaluate the Series 1 - x + x²/2! - x³/3! + … - x⁹/9!

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Subscribe to our Newsletter

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨