How to calculate the determinant of a 2X2 matrix in C++

1 Answer

0 votes
// determinant is a scalar-valued of the entries of a square matrix

#include <iostream>

#define SIZE 2
 
int main()
{
    float arr[SIZE][SIZE] = { { 3, 8 },{ 4, 6 } };
 
    /*
    *       a b
    * arr =
    *       c d
    *
    * determinant = a*d - b*c
    *
    */
 
    float determinant = (arr[0][0] * arr[1][1]) - (arr[0][1] * arr[1][0]);
 
    std::cout << determinant << "\n";
}

 
 
/*
run:
 
-14
 
*/

 



answered Dec 2, 2016 by avibootz
edited Sep 5, 2024 by avibootz

Related questions

1 answer 121 views
1 answer 209 views
1 answer 116 views
1 answer 123 views
1 answer 115 views
1 answer 121 views
1 answer 138 views
...