// Probability.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include #include using namespace std; double Success(double, int); int main() { double q; int z; std::cout << "Please enter a probability value: "; std::cin >> q; std::cout << "Please enter a Z-value: "; std::cin >> z; cout << Success(q, z); system("PAUSE"); return 0; } double Success(double q, int z) { double p = 1.0 - q; double lambda = z * (q / p); double sum = 1.0; int i, k; for (k = 0; k <= z; k++) { double poisson = exp(-lambda); // e^lambda for (i = 1; i <= k; i++) poisson * lambda / i; // lambda^1,2,3,4 divided by K!(1,2,3,4...) sum -= poisson * (1 - pow(q / p, z - k)); } return sum; }

C++ Port 4.8.1.

Demonstration purposes.