Given a number . The task is to find the N-th term in the following series:
14, 28, 20, 40, 32, 64…..
Input : N = 5 Output : 32 Input : N = 6 Output : 64
- Initialize first number with 14.
- Run a loop from i = 2 to N and do following steps:
- For Even i, double the previous term. For example if i = 2, current term will be 2*(term when i = 1), that is 2*14 = 28.
- For Odd i, subtract 8 from the previous term.
- Exit the loop and print the final number.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
In case you wish to attend live classes with industry experts, please refer DSA Live Classes