Find the Sum of the series 1 + 1/3 + 1/5 + 1/7 + … till N terms
Given a number N, the task is to find the sum of the below series till N terms.
Attention reader! Don’t stop learning now. Get hold of all the important mathematical concepts for competitive programming with the Essential Maths for CP Course at a student-friendly price. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
Input: N = 10
The sum of series 1 + 1/3 + 1/5 + 1/7 + 1/9 + 1/11 is 2.133256.
Input: N = 20
The sum of series 1 + 1/3 + 1/5 + 1/7 + … + 1/41 is 2.479674.
Approach: From the given series, find the formula for Nth term:
1st term = 1 2nd term = 1/3 3rd term = 1/5 4th term = 1/7 . . Nthe term = 1 / (2 * N - 1))
Nth term of the series*** QuickLaTeX cannot compile formula: *** Error message: Error: Nothing to show, formula is empty
Then iterate over numbers in the range [1, N] to find all the terms using the above formula and compute their sum.
Below is the implementation of the above approach:
Time Complexity: O(N)
Auxiliary Space: O(1)