Count of total Heads and Tails after N flips in a coin | Function to find count of head and tail ; Check if initially all the coins are facing towards head ; Check if initially all the coins are facing towards tail ; Driver code
function count_ht ( s , N ) { var p = [ 0 , 0 ] ; if ( s == ' ' ) { p [ 0 ] = Math . floor ( N / 2.0 ) ; p [ 1 ] = Math . ceil ( N / 2.0 ) ; } else if ( s == ' ' ) { p [ 0 ] = Math . ceil ( N / 2.0 ) ; p [ 1 ] = Math . floor ( N / 2.0 ) ; } return p ; } var C = ' ' ; var N = 5 ; var p = count_ht ( C , N ) ; document . write ( " " + ( p [ 0 ] ) + " " ) ; document . write ( " " + ( p [ 1 ] ) + " " ) ;