10 PRINT "binomial distribution"
20 PRINT
30 DIM M(3)
40 PRINT "(to end program enter 0)"
50 PRINT "number of trials";
60 INPUT N
70 IF N=0 THEN GOTO 320
80 PRINT "exact number of successes";
90 INPUT X
100 PRINT "probability of success":
110 INPUT P
120 PRINT
130 INPUT "Cumulative y/n";R$
140 SUM# = 0!
150 REM - compute the factorials
160 M(1) = N
170 M(2) = X
180 M(3) = N-X
190 FOR I=1  TO 3
200 IF M(I) = 0  THEN GOTO 260
210 A#=LOG(1)
220 FOR J=1  TO M(I)
230 A#=A#+LOG(J)
240 NEXT J
250 M(I) = A#
260 NEXT I
270 REM - using the computed factorials, compute prob.
280 R=EXP(M(1)-M(2)-M(3)+X*LOG(P)+(N-X)*LOG(1-P))
290 PRINT "probability of";X;"successes in";N;"trials =";R
300 PRINT
310 GOTO 50
320 END
2)-M(3)+X*LOG(P)+(N-X)*LO