#include <iostream>
using namespace std;



//Functions to get cofactor of mat[p][q] in temp[][]. n is current 
//dimension of mat[][]
void getCofactor(int mat[N][N], int temp[N][N], int p, int q, int n)
{
	int i = 0; , j= 0;

	//Looping for each element of the matrix
	for (int row=0;row < n; row++)
	{
		for (int col = 0;col <n;col++)
		{
			//Copying into the temporary matrix only those element 
			//Which are not in given row and column
			if (row!=p && col!=q)
			{
				temp[i][j++] = mat[row][col];

				//Row is filled ,so increase row index and 
				//reset col index
				if(j == n - 1)
				{
					j=0;
					i++;
				}
			}
		}
	}
}


/*Recrusive function for finding determinant of matrix. 
n is current dimension of mat[][]. */

int determinantOfMatix(int mat[N][N], int n)
{
	int D = 0;	//Initialize result


	//Base case : if matrix contains single element
	if( n==1 )
		return mat[0][0];
	int temp[N][N]; // To store cofactors
	int sign = 1; // To store sign multipierl 
	// Iterate for each element of list row
	for (int f=0; f< n;f++)
	{
		//Gettong Cofactor of mat [0][f]
		getCofactor(mat, temp, 0, n);
		D+=sign * determinantofMatrix(temp, n-1);
		// terms are to be added with alternate sign
		sign = -sign;
		}
		return D;
		}
		____main____
		int det=determinantofMatrix(mat, N );
			
