#include using namespace std; // The probability that a machine produces a defective product is // 1/3. What is the probability that the 1st defect occurs the on the // 5th item produced? int main() { double p = 1.0/3.0; // 1st defect int n = 5; auto geometric_dist = [](int n, double p) { // The geometric distribution is a special case of the negative // binomial distribution that deals with the number of Bernoulli // trials required to get a success (i.e., counting the number of // failures before the first success). // g(n,p) = q^(n-1) x p return pow(1-p, n-1) * p; }; cout << fixed << setprecision(3) << geometric_dist(n, p) << endl; return 0; }