#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 = 10; // defect probabilty double p = 0.12; // The first line should contain the probability that a batch of // 10 pistons will contain no more than 2 rejects. cout << fixed << setprecision(3) << binominal_probability(0,n,p) + binominal_probability(1,n,p) + binominal_probability(2,n,p) << endl; // The second line should contain the probability that a batch of // 10 pistons will contain at least 2 rejects. double out = 0; for (int x = 2; x <= 10; x++) out += binominal_probability(x,n,p); cout << fixed << setprecision(3) << out << endl; return 0; }