The determinant of the 2- by-2matrix |a11 a12| |a21 a22| is a11a22-a21a12 simila
ID: 3609055 • Letter: T
Question
The determinant of the 2- by-2matrix|a11 a12| |a21 a22| is a11a22-a21a12 similarly, the determinant of a3-by-3 matrix |a11 a12 a13| |a21 a22 a23| = a11|a22a23| - a21|a12 a13| + a31 |a12 a13| |a31 a32 a33| |a32a33| |a32a33| |a22 a23| using this information, write andtest two functions, named det 2( ) and det 3( ). The det 2( )function should accept the four coefficients of a 2-by-2 matrix andreturn its determinant. the det 3( ) function should accept thenine coefficients of a 3-by-3 matrix and return its determinant bycalling det 2( ) to calculate the required 2-by-2determinants. The determinant of the 2- by-2matrix
|a11 a12| |a21 a22| is a11a22-a21a12 similarly, the determinant of a3-by-3 matrix |a11 a12 a13| |a21 a22 a23| = a11|a22a23| - a21|a12 a13| + a31 |a12 a13| |a31 a32 a33| |a32a33| |a32a33| |a22 a23| using this information, write andtest two functions, named det 2( ) and det 3( ). The det 2( )function should accept the four coefficients of a 2-by-2 matrix andreturn its determinant. the det 3( ) function should accept thenine coefficients of a 3-by-3 matrix and return its determinant bycalling det 2( ) to calculate the required 2-by-2determinants.
Explanation / Answer
int det2(int, int, int,int);
int det3(int, int, int, int, int, int, int, int, int);
int main()
{
int a11, a12, a13, a21, a22, a23, a31, a32, a33;
cout << "Fora 2 X 2 matrix:" << endl;
cout << "Enter a11: ";
cin >> a11;
cout << "Enter a12: ";
cin >> a12;
cout << "Enter a21: ";
cin >> a21;
cout << "Enter a22: ";
cin >> a22;
cout << "The determinant is: " << det2(a11, a12,a21, a22) << endl;
cout << "Fora 3 X 3 matrix:" << endl;
cout << "Enter a11: ";
cin >> a11;
cout << "Enter a12: ";
cin >> a12;
cout << "Enter a13: ";
cin >> a13;
cout << "Enter a21: ";
cin >> a21;
cout << "Enter a22: ";
cin >> a22;
cout << "Enter a23: ";
cin >> a23;
cout << "Enter a31: ";
cin >> a31;
cout << "Enter a32: ";
cin >> a32;
cout << "Enter a33: ";
cin >> a33;
cout << "The determinant is: " << det3(a11, a12,a13,
a21, a22, a23, a31, a32, a33) <<endl;
cin.ignore();cin.ignore(); // this line isoptional
return 0;
}
int det2(int a11, int a12,int a21, int a22)
{
return a11*a22 - a21*a12;
}
int det3(int a11, int a12,int a13, int a21, int a22, int a23,
int a31, int a32, int a33)
{
return (a11*det2(a22, a23, a32, a33) - a21*det2(a12, a13,a32, a33)
+ a31*det2(a12, a13, a22, a23));
}