Determinant of Matrix in C language

 C program to find determinant of matrix

code:

#include <stdio.h>

void main()

   {

  int arr1[10][10],i,j,n;

  int det=0;

       printf("\n\nCalculate the determinant of a 3 x 3 matrix :\n");

       printf("-------------------------------------------------\n"); 

printf("Input elements in the first matrix :\n");

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

        {

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

            {

           printf("element - [%d],[%d] : ",i,j);

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

            }

        }  

printf("The matrix is :\n");

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

{

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

     printf("% 4d",arr1[i][j]);

    printf("\n");

}


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

      det = det + (arr1[0][i]*(arr1[1][(i+1)%3]*arr1[2][(i+2)%3] - arr1[1][(i+2)%3]*arr1[2][(i+1)%3]));


  printf("\nThe Determinant of the matrix is: %d\n\n",det);

}


Explanation:

  • This program is used to find the determinant of 3*3 matrix
  • This is a array based program
  • First we are declaring the array size and other variables in integer datatype.
  • Now we are using a for loop to enter the elements in an array like "element 0,0" which mean the element of first row and first column.

  • The for loop gets executed untill 9 elements because it is a 3*3 matrix
  • And finally to display the array we are using another for loop to print and display if.
Output:





Comments

Popular posts from this blog

Use of Backslash "\n" in C language

COHESION AND COUPLING material

Coding and Testing in software engineering