how do i fix the determinant part int det(int n, int matrix[][10]) { int d=0; in
ID: 640138 • Letter: H
Question
how do i fix the determinant part
int det(int n, int matrix[][10])
{
int d=0;
int c,sub1,i,j,sub2;
int submat[10][10];
if (n==2)
{
return((matrix[0][0]*matrix[1][1])-(matrix[1][0]*matrix[0][1])); }
else
{
for(c=0;c<n;c++)
{
sub1=0;
for(i=1;i<n;i++)
{
sub2=0;
for(j=0;j<n;j++)
{
if(j==c)
{
continue;
}
submat[sub1][sub2]=matrix[i][j];
sub2++;
}
sub1++;
}
d=d+(pow(-1,c)*matrix[0][c]*det(n-1,submat));
}
}
return d;
}
}
void main()
{
int matrix[10][10],transpose[10][10],product[10][10],submat[10][10];
int i,k, j, m,n,sum=0,d=0 ;
printf("Enter the order of the matrix : ") ;
scanf("%d %d", &m, &n) ;
printf("Enter the elements of the matrix : ") ;
for(i = 0 ; i < m ; i++)
{
for(j = 0 ; j < n ; j++)
{
scanf("%d", &matrix[i][j]) ;
}
}
printf(" The matrix A is: ") ;
for(i = 0 ; i < m ; i++)
{
for(j = 0 ; j < n ; j++)
{
printf("%5d", matrix[i][j]) ;
}
printf(" ");
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
transpose[j][i]=matrix[i][j];
}
}
printf("The Transpose of matrix A is : ");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%5d",transpose[i][j]);
}
}
printf(" ");
}
for(i=0;i<m;i++)
{
for(j=0;j<m;j++)
{
//product[i][j]=0;
sum=0;
for(k=0;k<n;k++)
{
sum+=matrix[i][k]*transpose[k][j];
}
product[i][j]=sum;
}
}
printf("The product of matrix A and A transpose is: ");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%5d",product[i][j]);
}
printf(" ");
}
printf(" the determinant is: ");
Explanation / Answer
#include #include int a[20][20],m; int determinant(int f[20][20],int a); int main() { int i,j; printf(" Enter order of matrix : "); scanf("%d",&m); printf(" Enter the elements of matrix "); for(i=1;iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.