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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!