1 3REM B I C O N F
 2 10 PRINT "DO YOU WANT INSTRUCTIONS (1=YES, 0=NO)";
 3 20 INPUT Y7
 4 30 IF Y7=1 THEN 700
 5 70 DEF FNA(V)=1E-4*INT(.5+1E6*V)
 6 75 PRINT "WHAT ARE X,N,C";
 7 80 INPUT Y,N,C
 8 90 LET P0=Y/N
 9 100 LET Q0=1-P0
10 110 LET G0=6*SQR(P0*Q0/N)
11 120 LET P1=P0-G0
12 130 IF P1>0 THEN 150
13 140 LET P1=0
14 150 LET P1=.1*INT(10*P1)
15 160 LET P2=P0+G0
16 170 IF P2<1 THEN 190
17 180 LET P2=1
18 190 LET P2=1-.1*INT(10-10*P2)
19 200 LET C0=.005*(100-C)
20 210 LET P=P1
21 220 LET T=Y-1
22 230 LET J=0
23 240 LET J=J-1
24 250 IF J=-7 THEN 310
25 260 LET P=P+10^J
26 270 GOSUB 520
27 280 IF 1-Z<C0 THEN 260
28 290 LET P=P-10^J
29 300 GOTO 240
30 310 LET L=P
31 320 LET P=P2
32 330 LET T=Y
33 340 LET J=0
34 350 LET J=J-1
35 360 IF J=-7 THEN 420
36 370 LET P=P-10^J
37 380 GOSUB 520
38 390 IF Z<C0 THEN 370
39 400 LET P=P+10^J
40 410 GOTO 350
41 420 LET U=P
42 430 PRINT
43 440 PRINT
44 450 PRINT "   BEST ESTIMATE OF POPULATION PROPORTION (PCT) = ";
45 460 PRINT FNA(Y/N)
46 470 PRINT
47 480 PRINT "   THE ";C;"PERCENT CONFIDENCE LIMITS ON THE POPULATION"
48 490 PRINT "   PROPORTION (PCT) ARE ";FNA(L);"AND ";FNA(U)
49 500 PRINT
50 510 STOP
51 520 LET Q=1-P
52 530 LET G=6*SQR(P*Q*N)
53 540 LET S=INT(N*P-G)
54 550 IF S>0 THEN 590
55 560 LET S=0
56 570 LET X=1
57 580 GOTO 630
58 590 LET X=P*N/S
59 600 FOR I=1 TO S-1
60 605 IF S=1 THEN 620
61 610 LET X=X*P*(N-I)/(S-I)
62 620 NEXT I
63 630 LET F=X*(Q^(N-S))
64 640 LET Z=F
65 650 FOR I=S+1 TO T
66 660 LET F=F*P*(N-I+1)/(Q*I)
67 670 LET Z=Z+F
68 680 NEXT I
69 690 RETURN
70 700 PRINT "THIS PROGRAM DETERMINES THE CONFIDENCE LIMITS"
71 710 PRINT "FOR A POPULATION PROPORTION BASED ON THE"
72 720 PRINT "EXACT BINOMIAL DISTRIBUTION.  ENTER VALUES"
73 730 PRINT "FOR X[SUCCESSES], N[SAMPLE SIZE], AND"
74 740 PRINT "C[CONFIDENCE COEFFICIENT IN PERCENT] WHEN"
75 750 PRINT "REQUESTED BY THE PROGRAM.  ADDITIONAL"
76 760 PRINT "INSTRUCTIONS MAY BE FOUND IN THE LISTING."
77 770 GO TO 70
78 9999 END