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 270
80 PRINT "EXACT NUMBER OF SUCCESSES";
90 INPUT X
100 PRINT "PROBABILITY OF SUCCESS";
110 INPUT P
119 REM - COMPUTE THE FACTORIALS
120 M(1)=N
130 M(2)=X
140 M(3)=N-X
150 FOR I=1 TO 3
160 IF M(I)=0 THEN 220
170 A=1
180 FOR J=1 TO M(I)
190 A=A*J
200 NEXT J
210 M(I)=LOG(A)
220 NEXT I
229 REM - USING THE COMPUTED FACTORIALS, COMPUTE PROBABILITY
230 R=EXP(M(1)-M(2)-M(3)+X*LOG(P)+(N-X)*LOG(1-P))
240 PRINT "PROBABILITY OF";X;"SUCCESSES IN";N;"TRIALS =";R
250 PRINT
260 GOTO 50
270 END
