Q:

Write a C program to find Determinant of Matrix

0

Write a C program to find determinant of matrix. Here’s simple program to find determinant of matrix in C Programming Language.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

What is Matrix ?


Matrix representation is a method used by a computer language to store matrices of more than one dimension in memory. C uses “Row Major”, which stores all the elements for a given row contiguously in memory.

Two-dimensional Arrays : :

The simplest form of multidimensional array is the two-dimensional array. A two-dimensional array is, in essence, a list of one-dimensional arrays. An m × n (read as m by n) order matrix is a set of numbers arranged in m rows and n columns.

To declare a two-dimensional integer array of size [x][y], you would write something as follows −

  • type arrayName [ x ][ y ];

Where type can be any valid C data type and arrayName will be a valid C identifier.

 
 
 

Below is the source code for C program to find determinant of matrix which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :

/*  C program to find determinant of matrix  */

#include <stdio.h>

int main()
{
    int A[2][2];
    int row, col;
    long det;

    /*
     * Reads elements in matrix A from user
     */
    printf("\nEnter values to the matrix 2x2 :: \n");
        for(row = 0; row<2; row++)
        {
            for(col = 0; col<2; col++)
            {
                 printf("\nEnter a[%d][%d] value :: ",row,col);
                 scanf("%d", &A[row][col]);
        }
    }

    /*
     * det(A) = ad - bc
     * a = A[0][0], b = A[0][1], c = A[1][0], d = A[1][1]
     */
    det = (A[0][0] * A[1][1]) - (A[0][1] * A[1][0]);

    printf("\nDeterminant of matrix A = %ld ", det);

    return 0;
}

Output : :


/*  C program to find determinant of matrix  */

Enter values to the matrix 2x2 ::

Enter a[0][0] value :: 3

Enter a[0][1] value :: 4

Enter a[1][0] value :: 5

Enter a[1][1] value :: 6

Determinant of matrix A = -2

Process returned 0

Above is the source code for C program to find determinant of matrix which is successfully compiled and run on Windows System.The Output of the program is shown above .

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Matrix Solved Programs – C Programming

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C program to check whether a Matrix is Identity Ma... >>
<< C program to find Transpose of matrix using Arrays...