Write a program that calls a function in order to compute the determinant of arr
ID: 3924423 • Letter: W
Question
Write a program that calls a function in order to compute the determinant of array X. Read a matrix from “testmat.txt” and display the determinant to the user.
Finding the determinant involves expanding along a row or column and summing the weighted determinants of the sub-matrices obtained by omitting that particular row and column. For example, expanding along the top row and computing the determinants of the sub-matrices directly, we have that the determinant for X as defined below is
.
Your function must use loops to compute the determinant. All I/O is to be done in your main() function. Example output is
The determinant of matrix
| -7 -3 3|
| 6 2 -3|
| 11 -5 8|
is 80.
Test on the following matrices:
can you please give me the answer to this question in C
Explanation / Answer
#include<stdio.h>
int main()
{
int b[3][3],row,col;
int det=0;
printf("enter elements: ");
for(row=0;row<3;row++)
for(col=0;col<3;col++)
scanf("%d",&b[row][col]);
printf(" the matrix is ");
for(row=0;row<3;row++){
printf(" ");
for(col=0;col<3;col++)
printf("%d ",b[row][col]);
}
for(row=0;row<3;row++)
det = det + (b[0][row]*(b[1][(row+1)%3]*b[2][(row+2)%3] - b[1][(row+2)%3]*b[2][(row+1)%3]));
printf(" Determinant for the given matrix is: %d",det);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.