Find probability that a player wins when probabilities of hitting the target are given | C ++ implementation of the approach ; Function to return the probability of the winner ; Driver Code ; Will print 9 digits after the decimal point
#include <bits/stdc++.h> NEW_LINE using namespace std ; double find_probability ( double p , double q , double r , double s ) { double t = ( 1 - p / q ) * ( 1 - r / s ) ; double ans = ( p / q ) / ( 1 - t ) ; return ans ; } int main ( ) { double p = 1 , q = 2 , r = 1 , s = 2 ; cout << fixed << setprecision ( 9 ) << find_probability ( p , q , r , s ) ; return 0 ; }