Below is a simple computer program for computing cumulative binomial probabilities--the probability that X or more "successes" will be observed in N independent trials if p0 is the probability of a success on each trial. The program is written in the Gauss computer language, but anyone familiar with Basic, Fortran, Pascal, C, or similar languages, should be able to translate it into one of those. In the first three commands you specify the values of N, X, and P0. For the values N = 10, X = 6, and P0 = .4 used here, the correct one-tailed p is 0.16623862.
n = 10;
x = 6;
p0 = .4;
r = (1-p0)/p0;
v = 1;
j = 0;
do until j = = n-x; [Most languages use a single equals sign, not the two shown
here.]
j = j+1;
v = v*r*(x+j)/(n-x+1-j)+1;
endo; [This marks the end of the loop started 3 lines above.]
p = v*p0^n;
print p;
The major disadvantage of this program is that v may be so large, and p0 n so small, that they may overflow or underflow the capacities of some computer languages. If you can compute v but not p0 n, you might replace formula in the next-to-last program line by the formula
p = exp(ln(v) + n*ln(p0)).