C Program to Calculate the Determinant of 2*2 Matrix

C Program to Calculate the Determinant of 2*2 Matrix

C program to calculate the determinant of 2*2 matrix

#include<stdio.h>

#include<conio.h>

int main()

{

          int a[2][2], i, j, d, e, c;

          printf("\n Enter elements of 2*2 matrix");

          for(i=0;i<2;i++)   // outer loop for taking row input 

          {

                   for(j=0;j<2;j++) // iner loop for taking colume input

                   {

                             scanf("%d", &a[i][j]);

                   }

          }

          for(i=0;i<2;i++)

          {

                   for(j=0;j<2;j++)

                   {

                             c= (a[0][0]*a[1][1]);

                             e= (a[0][1]*a[1][0]);

                             d=c-e;

                   }

          }

          printf("\n Determinant of 2*2 matrix is %d", d);

          getch();

}

Output
Determinant of 2*2 matrix
Step by step explanation 
The initial value of an array is 0, and the address of a matrix is made as below

Calculation of determinant of a matrix is
a[0][0] * a[1][1] - a[0][1] * a[1][0]

In this output
a[0][0] = 6
a[0][1] = 10
a[1][0] = 5
a[1][1] = 3

The determinant of the matrix in this example is 
c= (a[0][0]*a[1][1]);
c = 6*3
c = 18
and
  e= (a[0][1]*a[1][0]);
e = 10*5
e = 50
so, 
d = c-e
  d= 18-50
  d = -32




Post a Comment

0 Comments