# Minor of a determinant

• 11-30-2005
JHaney
Minor of a determinant
This is what I have for finding the minor. I think I could make it more condense to run faster but don't know what to do really. My program works with this function, but I'm just wondering what I can do to make it run smoother.

Code:

```double minor(double A[][4], int i, int j) {         double find_minor[3][3];         int counta = 0;         int countb = 0;         for (int x = 0; x < 4; x++)         {                 if (x != j)                 {                         for (int y = 0; y < 4; y++)                         {                                 if (y != i)                                 {                                         find_minor[counta][countb] = A[x][y];                                         ++countb;                                         if (countb % 3 == 0)                                         {                                                 countb = 0;                                         }                                 }                         }                         ++counta;                 }         }         double minordet = find_minor[0][0]*(find_minor[1][1]*find_minor[2][2]-find_minor[2][1]*find_minor[1][2]) -                 find_minor[0][1]*(find_minor[1][0]*find_minor[2][2]-find_minor[2][0]*find_minor[1][2])+find_minor[0][2] *                 (find_minor[1][0]*find_minor[2][1]-find_minor[2][0]*find_minor[1][1]);                 return minordet; }```
• 11-30-2005
Ancient Dragon
I don't know about the speed, but you should iniitlaize find_minor just to make sure no elements contain random data after that loop ends.
Code:

`double find_minor[3][3] = {0};`
loop counters should be from 0 to 3, not 0 to 4
Code:

```for (int x = 0; x < 3; x++) and for (int y = 0; y < 3; y++)```