PROGRAM BT1_10 PARAMETER (NMAX=12,P1=45.0/120.0,P2=25.0/120.0) INTEGER N,K N=10 PP=0.0 DO K=0,4 PP=PP+BERN(N,K,P1) ENDDO PP=1.0-PP WRITE(*,'(" XAC SUAT KHONG DUOI 5 NAM CO A XUAT HIEN=",F8.4)')PP PP=0.0 DO K=0,5 PP=PP+BERN(N,K,P2) ENDDO WRITE(*,'(" XAC SUAT KHONG QUA 5 NAM CO B XUAT HIEN=",F8.4)')PP 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