' ******************************************************************
' This program computes the binomial distribution B(N,P).
' For each value of K (K = 0..N), the probability Prob(X = K)
' is computed from function PBinom. The cumulative probability
' Prob(X <= K) is computed either by direct summation or by a
' call to function FBinom.
' ******************************************************************

#INCLUDE "fbmath.bi"

CONST N = 10   ' Number of repetitions
CONST P = 0.4  ' Probability of success

DIM AS INTEGER K
DIM AS DOUBLE  PK, S

CLS

PRINT USING "Binomial distribution: N = ###   P = #.####"; N; P
PRINT
PRINT " K    Prob(K)        Sum     FBinom"
PRINT "-----------------------------------"

S = 0
FOR K = 0 TO N
  PK = PBinom(N, P, K)
  S = S + PK
  PRINT USING "##    ##.####    ##.####    ##.####";_
              K; PK; S; FBinom(N, P, K)
NEXT K

SLEEP
