Given an integer N we need to find the geometric sum of the following series using recursion.
1 + 1/3 + 1/9 + 1/27 + … + 1/(3^n)
Input N = 5 Output: 1.49794 Input: N = 7 Output: 1.49977
In the above-mentioned problem, we are asked to use recursion. We will calculate the last term and call recursion on the remaining n-1 terms each time. The final sum returned is the result.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.