Question: Consider the following sequence: A = 0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23,9, 24, 8,... The first term


Consider the following sequence: A = 0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23,9, 24, 8,... The first term of the sequence is always zero, i.e., A[0] = 0 The remaining terms can be obtained using the following rule: A[n] = A[n - 1] -n But if A[n] is less than zero or A[n] already exists in the sequence, then A[n] = A[n - 1] + n For eg. A[0] = 1 A[1] = A[0] - 1 = 0 - 1 = -1 But since A[1] is less than 0, therefore A[1] = A[O] + 1 = 0 + 1 = 1 A[3] = A[2]- 3 = 3-3 = 0 But since A[3] = 0 already exists in the sequence as the first term of the sequence, so NO AN A[1] = A[0) - 1 = 0-12-1 But since All] is less than 0, therefore A[1] = A[0] + 1 = 0 + 1 = 1 A[3] = A[2] - 3 = 3 - 3 = 0 But since A[3] = 0 already exists in the sequence as the first term of the sequence, so A[3] = A[2] + 3 = 3 + 3 = 6 A[4] = A[3] - 4 = 6 - 4 = 2 Write a recursive function to display the n-th term of the above sequence. The function should take 'n' as input parameter. Once you upload files from your second device, click on Sync toch
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
