#include using namespace std; int fact(int n) { if(n == 1 || n == 0) return 1; return n * fact(n-1); } /* /n\ b(x,n,p) = | | * p^x * q^(n-x) \x/ */ double binominal_probability(int x, int n, double p) { int a = fact(n)/(fact(x)*fact(n-x)); double b = pow(p,x); double c = pow(1-p,n-x); return a*b*c; } int main() { // Number of trials int n = 6; // Ratio of boys being born double rboy = 1.09; // Ratio of girls being born double rgirl = 1; // Probability of giving birth to a boy double p = rboy/(rboy+rgirl); //what proportion of Russian families with exactly 6 children will // have at least 3 boys? // p(x >= 3) cout << fixed << setprecision(3) << binominal_probability(3,n,p) + binominal_probability(4,n,p) + binominal_probability(5,n,p) + binominal_probability(6,n,p) << endl; return 0; }