Computer Science Homework Help

Computer Science Homework Help. find the determinant of the matrix using C

Can anyone please debug it. It's supposed to find the determinant of the matrix and the problem is in the second function. I'm a beginner and it's due soon. I have spent 12+ hours straight on just debugging. TBH I just want someone to give me the fixed code and give a quick and simple how. Whoever can do that will be rewarded $10. The answers are supposed to be "The determinant of the matrix in matrix2.txt is 6080 The determinant of the matrix in matrix1.txt is -413 " heres the assignment lab1(5).pdf . assume that the header is fine as well as all the other parts cause i tested them. #include "lab1.h"

void findDeterminant(char filename[STRINGSIZE])

{

        int det = 0;

        int i, j;

        int matrix[MATSIZE][MATSIZE];

        FILE *fp3=fopen(filename, "r");

        for (i = 0; i<MATSIZE; i++)

                {

                for (j = 0; j < MATSIZE; j++)

                {

                fscanf(fp3,"%d",&matrix[i][j]);

                }

        }

        fclose(fp3);

        det = determinant (MATSIZE, matrix);

        printf("The determinant of the matrix in %s is %dn", filename, det);

}

int determinant(int n, int matrix[n][n])

{

        int det = 0;

        int power, i, j, l;

        int newMAT[n-1][n-1];

        if (n == 2)

        {

                det = (matrix[0][0]* matrix [1][1]) - (matrix[1][0]*matrix[0][1]);

                printf("the determinant of the 2x2 is %dn", det);

                return det;

        }

        else if (n == 1){

                det = matrix [0][0];

                return  det;

        }

        else {

                for(l=0;l<n;l++)

                {

                        int h = 0,k = 0;

                        for(i=1;i<n;i++)

                        {

                                for(j=0;j<n;j++)

                                {

                                        if(j==l)

                                          continue;

                                        newMAT[h][k] = matrix[i+1][j];

                                        k++;

                                        if(k == n-1)

                                                                                                                                                                 

                                        if(k == n-1)

                                        {

                                                h++;

                                                k=0;

                                        }

                                }

                        }

if (l%2 == 0)

{

det += matrix[0][l] * determinant ((n-1), newMAT);

return det;

}

else

{

det -= matrix[0][l] * determinant ((n-1), newMAT);

return det;

}

                }

}

}


Computer Science Homework Help

 
"Our Prices Start at $11.99. As Our First Client, Use Coupon Code GET15 to claim 15% Discount This Month!!"