Write a program that calculates the determinant of a 3 x 3 matrix.

\(\begin{vmatrix} a & b & c\\ d & e & f \\ g & h & i \end{vmatrix} = a \times \begin{vmatrix} e & f \\h & i \end{vmatrix}- b \times \begin{vmatrix} d & f \\g & i \end{vmatrix}+ c \times \begin{vmatrix} d & e \\g & h \end{vmatrix}= a \times (e \times i - f \times h) - b \times (d \times i - f \times g ) + c \times (d \times h - e \times g) \)


Difficulty level
This exercise is mostly suitable for students
#include <stdio.h>
#include <conio.h>
#define SIZE 3
void main()
{
	int A[SIZE][SIZE];    
 	int I, J;    /* counters */
 	int det;


 	for (I=0; I<SIZE; I++)
    		for (J=0; J<SIZE; J++)
        	{
         		printf("A[%d][%d] : ",I,J);
         		scanf("%d", &A[I][J]);
        	}


 	printf("\nMatrix :\n");
 	for (I=0; I<SIZE; I++)
    	{
     		for (J=0; J<SIZE; J++)
          		printf("%7d", A[I][J]);
     		printf("\n");
    	}

	det=0;
 	for(I=0;I<SIZE;I++)
     		det+=(A[0][I]*(A[1][(I+1)%SIZE]*A[2][(I+2)%SIZE] - A[1][(I+2)%SIZE]*A[2][(I+1)%SIZE]));

     	printf("Determinant = %d.\n", det);
	getch();
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Complexity of sum of square root