Find the Nth term of the series 14, 28, 20, 40,…..
Given a number
. The task is to find the N-th term in the following series:
14, 28, 20, 40, 32, 64…..
Examples:
Input : N = 5 Output : 32 Input : N = 6 Output : 64
Approach:
- 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:
C++
Java
Python 3
# Python 3 program to find the Nth term
# of the series 14, 28, 20, 40, …..
# Function to find the N-th term
def findNth(N):
# initializing the 1st number
b = 14
# loop from 2nd term to nth term
for i in range (2, N + 1):
# if i is even, double the
# previous number
if (i % 2 == 0):
b = b * 2
# if i is odd, subtract 8 from
# previous number
else:
b = b – 8
return b
# Driver Code
N = 6
print(findNth(N))
# This code is contributed
# by Akanksha Rai
C#
PHP
64
Recommended Posts:
- Find the Nth term of the series where each term f[i] = f[i - 1] - f[i - 2]
- Find Nth term of the series 1, 6, 18, 40, 75, ....
- Find Nth term of the series 1, 1, 2, 6, 24...
- the series 5, 13, 25, 41, 61...
- Find n-th term of series 1, 3, 6, 10, 15, 21...
- Find n-th term in the series 9, 33, 73,129 ...
- Find the nth term of the given series
- Find n-th term in series 1 2 2 3 3 3 4 4 4 4....
- Find Nth term of the series 3, 14, 39,, jit_t, Akanksha_Rai