Probability of getting two consecutive heads after choosing a random coin among two different types of coins | C ++ program to get the probability of getting two consecutive heads ; Function to return the probability of getting two consecutive heads ; Formula derived from Bayes 's theorem ; Driver code ; given the probability of getting a head for both the coins
#include <bits/stdc++.h> NEW_LINE using namespace std ; double getProbability ( double p , double q ) { p /= 100 ; q /= 100 ; double probability = ( p * p + q * q ) / ( p + q ) ; return probability ; } int main ( ) { double p , q ; p = 80 ; q = 40 ; cout << fixed << setprecision ( 15 ) << getProbability ( p , q ) << endl ; return 0 ; }