PROGRAM BT1_9 PARAMETER (NMAX=12,P=0.5) DIMENSION PK(0:NMAX) INTEGER N,K N=12 DO K=0,N PK(K)=BERN(N,K,P) ENDDO WRITE(*,*)' XAC SUAT TRONG MOT NAM CO: ' DO K=0,N WRITE(*,'(I3," THANG MA R-THANG > Rtb-THANG= ",F8.4)')K,PK(K) ENDDO END FUNCTION BERN(N,K,P) ! HAM NAY TINH XAC SUAT DE TRONG N LAN THI NGHIEM SU KIEN A XUAT ! HIEN K LAN, VOI P=P(A) BERN=COMBIN(N,K)*P**K*(1-P)**(N-K) RETURN END FUNCTION FAC(N) ! TINH N! (N GIAI THUA) REAL TMP IF (N.LT.0) THEN WRITE(*,*)' INVALID NUMERIC INPUT IN FAC FUNCTION' STOP ELSE IF (N.EQ.0.OR.N.EQ.1) THEN FAC=1.0 RETURN ELSE TMP=1.0 DO I=2,N TMP=TMP*REAL(I) ENDDO FAC=TMP RETURN ENDIF END FUNCTION COMBIN(N,K) ! TINH TO HOP CHAP K CUA N ! FUNCTION/SUBROUTINE DUOC GOI TOI: FAC(N) IF (N.LT.0.OR.K.LT.0.OR.N.LT.K) THEN WRITE(*,*)' INVALID NUMERIC INPUT IN COMBIN FUNCTION' STOP ELSE COMBIN=FAC(N)/FAC(K)/FAC(N-K) RETURN ENDIF END