Explain the functionality of below recursive functions.
Answer: Total numbers of stars printed is equal to 1 + 2 + …. (n-2) + (n-1) + n, which is n(n+1)/2.
Answer: For a positive n, fun2(n) prints the values of n, 2n, 4n, 8n … while the value is smaller than LIMIT. After printing values in increasing order, it prints same numbers again in reverse order. For example fun2(100) prints 100, 200, 400, 800, 800, 400, 200, 100.
If n is negative, the function is returned immediately.
Please write comments if you find any of the answers/codes incorrect, or you want to share more information about the topics discussed above.
- Practice Questions for Recursion | Set 6
- Practice Questions for Recursion | Set 7
- Practice Questions for Recursion | Set 5
- Practice Questions for Recursion | Set 4
- Practice Questions for Recursion | Set 2
- Practice Questions for Recursion | Set 1
- Practice questions for Linked List and Recursion
- Recursive Practice Problems with Solutions
- Find the value of ln(N!) using Recursion
- Sum of the series 1^1 + 2^2 + 3^3 + ..... + n^n using recursion
- Tail Recursion
- Generating subarrays using recursion
- Generating all possible Subsequences using Recursion
- Program to Calculate e^x by Recursion