Find the Nth element of the modified Fibonacci series | Function to return the Nth number of the modified Fibonacci series where A and B are the first two terms ; To store the current element which is the sum of previous two elements of the series ; This loop will terminate when the Nth element is found ; Return the Nth element ; Driver code
function findNthNumber ( A , B , N ) { var sum = 0 ; for ( i = 2 ; i < N ; i ++ ) { sum = A + B ; A = B ; B = sum ; } return sum ; } var A = 5 , B = 7 , N = 10 ; document . write ( findNthNumber ( A , B , N ) ) ;