Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!
You have been given a series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!, find out the sum of the series till nth term.
Examples :
Input :n = 5
Output : 2.70833
Input :n = 7
Output : 2.71806
A simple solution is to one by one computer terms. For every term, find its corresponding factorial value.
An efficient solution is to do factorial computations in same loop.
CPP
Java
Python3
C#
PHP
Javascript
Output:
Sum: 2.70833
Time Complexity: O(n)
Auxiliary Space: O(1), since no extra space has been taken.
Last Updated :
16 Feb, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...