**C program to find determinant of Matrix** : The **determinant of a matrix** is a **number** that can be calculated from the matrix. It tells us things about the matrix that are useful in systems of linear equations, in calculus and more. First of all, if you want to calculate the determinant of matrix then your matrix should be an square matrix i.e. MxM , otherwise determinant will not exist.

If you wish to calculate determinant of 3×3 matrix then formula will be something like below :

Say 3×3 matrix is :

Then its determinant will be like below:

Note : | | denotes determinant . That means 3 x 3 matrix has been broken into 3 small determinants

Now consider an example of 4×4 matrix :

Notice the + – + – pattern (+a… -b… +c… -d…). This is important to remember.

The pattern continues for 5×5 matrices and higher.

Now let us see how to write a C program to find determinant of Matrix MxM . The program will accept the order of matrix i.e. M as input from user and then ask user to enter the values of matrix elements. Then it will calculate the determinant of the matrix and returns the output.

### C program to find determinant of Matrix :

#include<conio.h> #include<stdio.h> int a[20][20],m; int determinant(int f[20][20],int a); int main() { int i,j; printf("----------------------------------------------------------------------\n"); printf("-------------------made by C code champ ------------------------------\n"); printf("----------------------------------------------------------------------\n"); printf("\n\nEnter order of matrix : "); scanf("%d",&m); printf("\nEnter the elements of matrix\n"); for(i=1;i<=m;i++) { for(j=1;j<=m;j++) { printf("a[%d][%d] = ",i,j); scanf("%d",&a[i][j]); } } printf("\n\n---------- Matrix A is --------------\n"); for(i=1;i<=m;i++) { printf("\n"); for(j=1;j<=m;j++) { printf("\t%d \t",a[i][j]); } } printf("\n \n"); printf("\n Determinant of Matrix A is %d .",determinant(a,m)); getch(); } int determinant(int f[20][20],int x) { int pr,c[20],d=0,b[20][20],j,p,q,t; if(x==2) { d=0; d=(f[1][1]*f[2][2])-(f[1][2]*f[2][1]); return(d); } else { for(j=1;j<=x;j++) { int r=1,s=1; for(p=1;p<=x;p++) { for(q=1;q<=x;q++) { if(p!=1&&q!=j) { b[r][s]=f[p][q]; s++; if(s>x-1) { r++; s=1; } } } } for(t=1,pr=1;t<=(1+j);t++) pr=(-1)*pr; c[j]=pr*determinant(b,x-1); } for(j=1,d=0;j<=x;j++) { d=d+(f[1][j]*c[j]); } return(d); } }

We hope you all have enjoyed the C program to find determinant of Matrix. If you have any issues with the above code or logic of above code then ask us in form of comment.

NidhinSeptember 17, 2012 at 3:20 pm -Very simple program but powerfull.Thanks pal……….

wow goldOctober 10, 2012 at 10:56 pm -Itˇs really a nice and helpful piece of info. I am glad that you just shared this helpful info with us. Please keep us up to date like this. Thanks for sharing.

Reda BrackinNovember 6, 2012 at 7:25 pm -You are so gifted! Count your self fortunate

saraDecember 3, 2012 at 9:27 pm -slt je veux un programme pour calculer det(A)=0, A est une matrice, a un variable . je veux calculer det(A)=0 pour trouver ce variable (je vais tomber sur une polynome de degré 6, et je dois calculer les racines de cette polynome). merci d’avance

saraDecember 4, 2012 at 10:07 am -i want program to calcul the “valeur propre” d’une matrice 4*4 en utilisant polynome caracteristique

AdeoluJanuary 18, 2013 at 5:52 am -pls i dont knw if you can help write dis same code in c++ bcos am having problems writing it in c++.thanks

Crea TorrMarch 9, 2013 at 9:12 pm -Can u plz tll me “What is the use of t ,and incrementing it if it not further used in program?”