PROGRAM BT2_4 PARAMETER (NMAX=100) DIMENSION X(NMAX) INTEGER NAM(NMAX),N,I,K REAL G(4),T(4) OPEN(1,FILE='C:\MASTER\G_TR\BAITAP~1\NEW\BANG3.TXT') READ(1,*) READ(1,*) READ(1,*)N READ(1,*)((NAM(I),X(I)), I=1,N) DO K=1,4 G(K)=AMMGOC(X,N,K) T(K)=AMMTAM(X,N,K) ENDDO WRITE(*,*)' CAC MOMEN TINH BANG PHUONG PHAP TRUC TIEP' WRITE(*,*)' BAC ',' MOMEN GOC ',' MOMEN TAM ' DO K=1,4 WRITE(*,'(I5,2F20.3)') K, G(K), T(K) ENDDO END FUNCTION AMMGOC(X,N,K) ! ! HAM NAY TINH MOMEN GOC BAC K CUA CHUOI SO LIEU ! INPUT: + X MANG SO LIEU BAN DAU DO DAI N ! + N DUNG LUONG MAU ! + K BAC CUA MOMEN ! OUTPUT: MOMEN GOC BAC K ! DIMENSION X(N) INTEGER N,K,I REAL TMP TMP=0.0 DO I=1,N TMP=TMP+X(I)**K ENDDO AMMGOC=TMP/REAL(N) 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 FUNCTION AMMTAM(X,N,K) ! HAM NAY TINH MOMEN TRUNG TAM BAC K TU CHUOI SO LIEU X ! INPUT: + X MANG SO LIEU BAN DAU DO DAI N ! + N DUNG LUONG MAU ! + K BAC CUA MOMEN ! OUTPUT: MOMEN TRUNG TAM BAC K ! FUNCTION/SUBROUTINE DUOC GOI TOI: AMMGOC(X,N,K), COMBIN(N,K) DIMENSION X(N) INTEGER N,K,I REAL TMP,TB TB=AMMGOC(X,N,1) TMP=0 DO I=0,K TMP=TMP+(-1)**I*COMBIN(K,I)*TB**I*AMMGOC(X,N,K-I) ENDDO AMMTAM=TMP RETURN END