Find probability that a player wins when probabilities of hitting the target are given | Function to return the probability of the winner ; Driver Code ; Will print 9 digits after the decimal point
function find_probability ( p , q , r , s ) { var t = ( 1 - p / q ) * ( 1 - r / s ) ; var ans = ( p / q ) / ( 1 - t ) ; return ans ; } var p = 1 , q = 2 , r = 1 , s = 2 ; document . write ( find_probability ( p , q , r , s ) . toFixed ( 9 ) ) ;