CA50
Forerunner
Please help me with this code to calclualte the determinant of a matrix using column operation. The problem is when the element r3c3 (assuming it to be a 3x3 matrix) has to be converted to 0
Code:
/*FUNCTION TO CALCULATE THE DETERMINANT OF A MATRIX
PARAMETER : SINGLE VALUE OF ROW AND COL IS PASSED, AS FOR ALL THE MATRIX, THE VALUE OF ROW AND COL WILL BE SAME | IN ALL THE CASE THE COLOUMN VALUE IS MANDATORY SO ITS SET TO 'col', WHICH IS AGAIN PREDEFINED*/
float matrix_determinant(int row, float matrix[][row])
{
int i, j, k,flag=0,counter,count;
float determinant=0,temp,element;
for(i=0; i<row; i++)
{
flag=0;
for(j=0; j<row; j++)
{
//counter++;
if(i == j)
{
temp = 1 / matrix[i][j];
determinant = determinant + temp;
counter = i;
for(k=0; k<row; k++)
{
printf("\nRow-%d,Col-%d : %f = %f * %f ",i,k,matrix[i][k],matrix[i][k],temp);
matrix[i][k] = matrix[i][k] * temp;
}
break;
}
if((i>j) && (flag == 0))
{
temp = matrix[i][j];
printf("\n\nValue of the term to be multiplied : %f\n",temp);
for(k=0; k<row; k++)
{
printf("\nRow-%d,Col-%d : %f = %f - (%f * %f)",i,k,matrix[i][k],matrix[i][k],temp,matrix[counter][k]);
matrix[i][k] = matrix[i][k] - (temp * matrix[counter][k]);
}
printf("\n.........................................\n");
matrix_display(row, matrix);
flag = 1;
}
}
printf("\n-----------------------------------------\n");
matrix_display(row, matrix);
}
return determinant;
}