Answer to Question #132677 in C++ for KA

Question #132677
Consider A is 3*3 matrix find the determinant of a matrix A and print it
1
Expert's answer
2020-09-12T11:39:34-0400
#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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS