Skip to main content

Program to calculate the determinant of 2×2 matrix.

Program to calculate the determinant of 2×2 matrix.


CODE

👇

  1. #include<stdio.h>
  2. #include<conio.h>

  3. void main()
  4. {
  5.     int a[2][2], i, j;
  6.     long determinant;

  7.     printf("Enter the 4 elements of matrix  :\n");
  8.     for (i = 0; i < 2; i++)
  9.     {
  10.         for (j = 0; j < 2; j++)
  11.         {
  12.             scanf("%d", &a[i][j]);
  13.         }
  14.     }

  15.     printf("\nThe matrix is : \n");
  16.     for (i = 0; i < 2; i++)
  17.     {
  18.         printf("\n");
  19.         for (j = 0; j < 2; j++)
  20.         {
  21.             printf("%d\t", a[i][j]);
  22.         }
  23.     }

  24.     determinant = a[0][0] * a[1][1] - a[1][0] * a[0][1];

  25.     printf("\nDeterminant of 2X2 matrix: %ld", determinant);
  26. }

👉Execute👈


//OUTPUT
/*
Enter the 4 elements of matrix  :
2
2
6
8

The matrix is : 

2 2
6 8
Determinant of 2X2 matrix: 4
*/









                                                                               //ThE ProFessoR