#include "Matrix.h" void minor(matrix *m, short delete_row, short delete_col, matrix *ans); void minor(matrix *m, short delete_row, short delete_col, matrix *ans) { short rr, ra, cc, ca; /* Create space for answer matrix here */ /* FAILS if delete_row is not between 0 and m->rows-1 delete_col is not between 0 and m->cols-1 m->rows==1 or m->cols==1 */ NewMatrix(ans,m->rows-1,m->cols-1); for(rr=0, ra=0; rrrows; rr++) { if(rr==delete_row) continue; for(cc=0,ca=0;cccols;cc++) { if(cc==delete_col) continue; ans->st[ans->cols*ra+ca]=m->st[m->cols*rr+cc]; ca++; } ra++; } } short det(matrix *m); /* FAILS if matrix is not square */ short det(matrix *m) { short ans, cc, sign; matrix tmp; if(m->rows==1) return m->st[0]; ans=0; for(cc=0, sign=1;cccols;cc++, sign=-sign) { minor(m,0,cc,&tmp); ans+=sign*m->st[cc]*det(&tmp); DisposeMatrix(&tmp); } return ans; }