Print a sequence of numbers starting with N, without using loop, in which A[i+1] = A[i] - 5, if A[i]>0, else A[i+1]=A[i] + 5 repeat it until A[i]=N.
The first line contains an integer T, number of test cases. Then following T lines contains an integer N.
For each test case, print the pattern in newline with space separated integers.
0< N < 10000
16 11 6 1 -4 1 6 11 16
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 by one add 5 until we reach N.
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.