Find the determinant of a matrix with C.
#include <stdio.h>
int main()
{
int A[2][2];
int row, col;
long det;
/* Input elements in matrix A from user */
printf("Enter elements in matrix of 2 2x2: \n");
for (row = 0; row < 2; row++)
{
for (col = 0; col < 2; col++)
{
scanf("%d", &A[row][col]);
}
}
/*
* det(A) = ad - bc
* a = A[0][0], b = A[0][1], c = A[1][0], d = A[1][1]
*/
det = (A[0][0] * A[1][1]) - (A[0][1] * A[1][0]);
printf("Determinant of matrix A = %ld", det);
return 0;
}
Output
Enter elements in matrix of size 2x2 :
1 2
3 4
Determinant of matrix A = -2
0 Comments