|a11 a12| |a21 a22| is a11a22-a21a12 similarly, the determinant of a 3-by-3 matr
ID: 3609078 • Letter: #
Question
|a11 a12| |a21 a22| is a11a22-a21a12 similarly, the determinant of a 3-by-3 matrix |a11 a12 a13| |a21 a22 a23| = a11|a22 a23| - a21|a12 a13| + a31|a12 a13| |a31 a32 a33| |a32a33| |a32a33| |a22 a23| using this information, write and test two functions, nameddet 2( ) and det 3( ). The det 2( ) function should accept the fourcoefficients of a 2-by-2 matrix and return its determinant. the det3( ) function should accept the nine coefficients of a 3-by-3matrix and return its determinant by calling det 2( ) to calculatethe required 2-by-2 determinants. |a21 a22| is a11a22-a21a12 similarly, the determinant of a 3-by-3 matrix |a11 a12 a13| |a21 a22 a23| = a11|a22 a23| - a21|a12 a13| + a31|a12 a13| |a31 a32 a33| |a32a33| |a32a33| |a22 a23| using this information, write and test two functions, nameddet 2( ) and det 3( ). The det 2( ) function should accept the fourcoefficients of a 2-by-2 matrix and return its determinant. the det3( ) function should accept the nine coefficients of a 3-by-3matrix and return its determinant by calling det 2( ) to calculatethe required 2-by-2 determinants.Explanation / Answer
void main()
{
int determinant(int[5][5],int);
void read(int[5][5],int);
void print(int[5][5],int);
int a[5][5],l,n;
int result;
l1:clrscr();
cout<<"Enter Order Of Matrix(MAX. Of 4X4):";
cin>>l>>n;
if(l!=n)
{
cout<<"SORRY!!!!! Only Squarematrix";
goto l1;
}
read(a,n);
result = determinant(a,n);
print(a,n);
cout<<"The Determinant of the above matrixis:"<<result;
getch();
}
void print(int b[5][5],int m)
{
clrscr();
cout<<"MATRIX IS :-";
for(int i=0;i<m;i++)
{
cout<<"";
for(int j=0;j<m;j++)
cout<<" "<<b[i][j];
}
}
int determinant(intb[5][5],int m)
{
int i,j,sum = 0,c[5][5];
if(m==2)
{
sum = b[0][0]*b[1][1] -b[0][1]*b[1][0];
return sum;
}
for(int p=0;p<m;p++)
{
int h = 0,k = 0;
for(i=1;i<m;i++)
{
for( j=0;j<m;j++)
{
if(j==p)
continue;
c[h][k] = b[i][j];
k++;
if(k == m-1)
{
h++;
k = 0;
}
}
}
sum = sum +b[0][p]*pow(-1,p)*determinant(c,m-1);
}
return sum;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.