Question: 4. Pattern Print Given a number n, print following pattern without using any loop. Input: n = 16 Output: 16, 11, 6, 1, -4, 1,
4. Pattern Print
Given a number n, print following pattern without using any loop.
Input: n = 16
Output: 16, 11, 6, 1, -4, 1, 6, 11, 16
Input: n = 10
Output: 10, 5, 0, 5, 10
We basically first reduce 5 one by one until we reach a negative or 0. After we reach 0 or negative, we one add 5 until we reach n. Hint: think in terms of recursion
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
