------------------------------------------------------------------------------------------------------------------------------------
PROGRAM deterMINan
IMPLICIT NONE
INTEGER::i,j,g,f,r,j1,k,s,n
REAL::landa,t
REAL,ALLOCATABLE::a(:,:),b(:)
PRINT*
PRINT*," for matrix(n,n) input n : "
READ*,n
ALLOCATE (a(n,n),b(n))
DO g=1,n
PRINT*," input line",g,":"
READ*,a(g,:)
END DO
k=0
DO i=1,n
IF (a(i,i)==0) THEN
DO j=i+1,n
IF (a(j,i)/=0) THEN
k=k+1
b=a(j,:)
a(j,:)=a(i,:)
a(i,:)=b
END IF
END DO
END IF
DO j1=i+1,n
landa=-a(j1,i)/a(i,i)
a(j1,:)=(landa*a(i,:))+a(j1,:)
END DO
END DO
PRINT*
PRINT*
t=1
DO s=1,n
t=t*a(s,s)
END DO
IF (MOD(k,2)==0) THEN
PRINT*," DeterMINant = ",t
ELSE
PRINT*," DeterMINant = ",-t
END IF
PRINT*
PRINT*,"-----------------------------------------------------------------"
END