Probability of not getting two consecutive heads together in N tosses of coin | javascript implementation to find the probability of not getting two consecutive heads together when N coins are tossed ; Function to compute the N - th Fibonacci number in the sequence where a = 2 and b = 3 ; The first two numbers in the sequence are initialized ; Base cases ; Loop to compute the fibonacci sequence based on the first two initialized numbers ; Function to find the probability of not getting two consecutive heads when N coins are tossed ; Computing the number of favourable cases ; Computing the number of all possible outcomes for N tosses ; Driver code
function round ( vr , digit ) { var value = parseInt ( ( vr * Math . pow ( 10 , digit ) + .5 ) ) ; return value / Math . pow ( 10 , digit ) ; } function probability ( N ) { var a = 2 ; var b = 3 ; if ( N == 1 ) { return a ; } else if ( N == 2 ) { return b ; } else { for ( i = 3 ; i <= N ; i ++ ) { var c = a + b ; a = b ; b = c ; } return b ; } } function operations ( N ) { var x = probability ( N ) ; var y = parseInt ( Math . pow ( 2 , N ) ) ; return round ( x / y , 2 ) ; } var N = 10 ; document . write ( ( operations ( N ) ) ) ;