# Program for calculating Determinant of two 2D matrix

```#include<stdio.h>                            //INCLUDING HEADER FILES
#include<math.h>

int mat[20][20],index[20][20],n,d[20];                    //DECLARING GLOBAL VARIABLES
void calc(int);                                //FUNCTION calc() DECLERED HERE

main()                                    //FUNCTION main() STARTS HERE
{
int a,i,j;                            //DECLARING LOCAL VARIABLES FOR main()
printf("\n          ENTER THE ORDER ::");            //GETTING THE ORDER OF DETERMINANT
scanf("%d",&n);
printf("\n          ENTER THE MATRIX ::");            //GETTING THE DETERMINANT
for(i=0;i<n;i++)                        //ROWWISE
for(j=0;j<n;j++)
scanf("%d",&mat[i][j]);
for(i=0;i<n;i++)
index[n-1][i]=i;
a=n-1;
calc(a);                            //CALLING THE FUNCTION calc() WITH PARAMETER a

printf("\n          VALUE OF THE DETERMINANT \n\n");        //PRINTING THE DETERMINANT ...
for(i=0;i<n;i++)
{
printf("             ");
for(j=0;j<n;j++)
printf("%5d",mat[i][j]);
printf("\n");
}
printf("\n          IS EQUAL TO %d\n\n",d[a]);            //....AND ITS VALUE
}                                    //END OF main()

void calc(int i)                            //FUNCTION calc()'S DEFINITION STARTS HERE
{
int j,k,t;                            //DECLARING LOCAL VARIABLES FOR calc()
for(j=0;j<=i;j++)
{
t=0;
for(k=0;k<=i;k++)
{
if(j==k)
continue;
else
{
index[i-1][t]=index[i][k];
t++;
}
}
if(i>2)
if(i==2)
d[i]+=(mat[n-2][index[1][0]]*mat[n-1][index[1][1]]-mat[n-1][index[1][0]]*mat[n-2][index[1][1]])*mat[n-3][index[i][j]]*pow(-1,(n-i-1)+(index[i][j]));
else
d[i]+=mat[n-i-1][index[i][j]]*d[i-1]*pow(-1,(n-i-1)+(index[i][j]));
}
}                                    //END OF calc()
```

## 4 thoughts on “Program for calculating Determinant of two 2D matrix”

Like

2. It’s a pity that people don’t realize the importance of this information. Thanks for posing it.

Like

3. I have been looking looking around for this kind of information. Will you post some more in future? I’ll be grateful if you will.

Like

4. Keep up the good work, I like your writing.

Like