Question #132677

Consider A is 3*3 matrix find the determinant of a matrix A and print it

Expert's answer

#include <iostream>

int main()
{
    const size_t SIZE { 3 };
    float mat[SIZE][SIZE] = {
        {6.f,  1.f, 1.f },
        {4.f, -2.f, 5.f },
        {2.f,  8.f, 7.f }
    };
    float det =
            mat[0][0] * mat[1][1] * mat[2][2] + // diag
            mat[0][2] * mat[1][0] * mat[2][1] +
            mat[0][1] * mat[1][2] * mat[2][0] -
            mat[0][2] * mat[1][1] * mat[2][0] - // diag
            mat[0][0] * mat[1][2] * mat[2][1] -
            mat[0][1] * mat[1][0] * mat[2][2];
    std::cout << "Determinant is: " << det << "\n";
    return 0;
}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS