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

\(\begin{vmatrix} a & b \\c & d \end{vmatrix} = a \times d - b \times c\)


Difficulty level
This exercise is mostly suitable for students
#include <stdio.h>
#include <conio.h>
#define SIZE 2
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=A[0][0]*A[1][1]-+A[0][1]*A[1][0];

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

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
N-ary tree