rendered paste bodydouble det(sMatrix mat) {
//Test to make sure the matrix is square.
if(mat.cols != mat.rows) error("Matrix is not square!");
//If the matrix is a 1x1, return the number
if(mat.cols==1 && mat.rows ==1) {
return (mat.data[0]);
} else if(mat.cols==2 && mat.rows==2) {
return((mat.data[0]*mat.data[3])-(mat.data[2]*mat.data[1]));
} else {
sMatrix recurDet;
recurDet.cols=(mat.cols-1);
recurDet.rows=(mat.rows-1);
double matDet;
matDet=0;
int loop; int looptwo; int accum;
for(loop=1; loop<=mat.cols; loop++) {
accum=0;
recurDet.data=(double *)malloc(((mat.cols-1)*(mat.rows-1))*sizeof(double));
recurDet.data=(double*)malloc(1000);
// recurDet.data[0]=5;
for(looptwo=mat.cols;looptwo<(mat.rows*mat.cols);looptwo++) {
if(looptwo%mat.cols != loop) {
recurDet.data[accum]=mat.data[looptwo];
accum++;
}
}
matDet+=mat.data[loop-1]*det(recurDet);
free(recurDet.data);
}
return (matDet);
}
}