Check if the n | Javascript Program to check if the nth is odd or even in a sequence where each term is sum of previous two term ; Return if the nth term is even or odd . ; Return true if odd ; Driven Program
var MAX = 100 ; function findNature ( a , b , n ) { var seq = Array ( MAX ) . fill ( 0 ) ; seq [ 0 ] = a ; seq [ 1 ] = b ; for ( var i = 2 ; i <= n ; i ++ ) seq [ i ] = seq [ i - 1 ] + seq [ i - 2 ] ; return ( seq [ n ] & 1 ) ; } var a = 2 , b = 4 ; var n = 3 ; ( findNature ( a , b , n ) ? ( document . write ( " " + " " ) ) : ( document . write ( " " + " " ) ) ) ;