import java.io.*;
import java.lang.*;
class Matrixdet{
public static double determinent(int b[][],int m)
{
int c[][]=new int[m][m];
int i,j,k;
double sum=0;
if(m==1) { sum=b[0][0]; }
else if(m==2)
{
sum=(( b[0][0]*b[1][1] ) - ( b[0][1]*b[1][0] ));
}
else
{
for(int p=0;p<m;p++)
{
int h=0;k=0;
for(i=1;i<m;i++)
{
for(j=0;j<m;j++)
{
if(j==p)
continue;
c[h][k]=b[i][j];
k++;
if(k==m-1)
{
h++;
k=0;
}
}
}
sum=sum+b[0][p]*Math.pow((-1),p)*determinent(c,m-1);
}
}
return sum;
}
public static void main(String[] args) throws IOException{
DataInputStream in=new DataInputStream(System.in);
System.out.println("\nMATRIX :");
System.out.print("\nENTER THE ORDER OF THE MATRIX YOU HAVE : ");
int order=Integer.parseInt(in.readLine());
int[][] A = new int[order][order];
System.out.println("\nENTER ELEMENTS OF MATRIX : ");
for (int i=0 ; i < order ; i++)
for (int j=0 ; j < order ; j++)
{
A[i][j] = Integer.parseInt(in.readLine());
}
System.out.println("MATRIX : ");
for (int i=0 ; i < order ; i++)
{ System.out.println();
for (int j=0 ; j < order ; j++)
{
System.out.print(A[i][j]+" ");
}
}
System.out.println();
System.out.println("\nDETERMINENT OF MATRIX : "+ determinent(A,order));
}
}
import java.lang.*;
class Matrixdet{
public static double determinent(int b[][],int m)
{
int c[][]=new int[m][m];
int i,j,k;
double sum=0;
if(m==1) { sum=b[0][0]; }
else if(m==2)
{
sum=(( b[0][0]*b[1][1] ) - ( b[0][1]*b[1][0] ));
}
else
{
for(int p=0;p<m;p++)
{
int h=0;k=0;
for(i=1;i<m;i++)
{
for(j=0;j<m;j++)
{
if(j==p)
continue;
c[h][k]=b[i][j];
k++;
if(k==m-1)
{
h++;
k=0;
}
}
}
sum=sum+b[0][p]*Math.pow((-1),p)*determinent(c,m-1);
}
}
return sum;
}
public static void main(String[] args) throws IOException{
DataInputStream in=new DataInputStream(System.in);
System.out.println("\nMATRIX :");
System.out.print("\nENTER THE ORDER OF THE MATRIX YOU HAVE : ");
int order=Integer.parseInt(in.readLine());
int[][] A = new int[order][order];
System.out.println("\nENTER ELEMENTS OF MATRIX : ");
for (int i=0 ; i < order ; i++)
for (int j=0 ; j < order ; j++)
{
A[i][j] = Integer.parseInt(in.readLine());
}
System.out.println("MATRIX : ");
for (int i=0 ; i < order ; i++)
{ System.out.println();
for (int j=0 ; j < order ; j++)
{
System.out.print(A[i][j]+" ");
}
}
System.out.println();
System.out.println("\nDETERMINENT OF MATRIX : "+ determinent(A,order));
}
}