#include typedef float DATATYPE ;
DATATYPE ** Allot_Det_Mem(int iDetOrder);
void Delete_Det_Mem(DATATYPE **ppiHead,int iDetOrder);
float Count_Det(DATATYPE **ppiHead,int iDetOrder);
int main(int argc, char* argv[])
{
int iDetOrder = 0;
DATATYPE **ppiDetArrayHead = NULL;
int x = 0,y = 0;
printf("please input the Det order!\n");
scanf("%d",&iDetOrder);
ppiDetArrayHead = Allot_Det_Mem(iDetOrder);
for(y = 0; y < iDetOrder; y++)
{
printf("%d line:\n",y+1);
for(x = 0; x < iDetOrder; x++)
{
scanf("%f",*(ppiDetArrayHead+y)+x);
}
}
for(y = 0; y < iDetOrder; y++)
{
for(x = 0; x < iDetOrder; x++)
{
printf("%f ",*(*(ppiDetArrayHead+y)+x));
}
printf("\n");
}
printf("Value = %f\n",Count_Det(ppiDetArrayHead,iDetOrder));
Delete_Det_Mem(ppiDetArrayHead,iDetOrder);
return 0;
}
DATATYPE ** Allot_Det_Mem(int iDetOrder)
{
DATATYPE **ppiHead = NULL;
int index = 0;
ppiHead = (DATATYPE **)malloc(sizeof(DATATYPE *));
for(index = 0; index < iDetOrder; index++)
{
*(ppiHead+index) = (DATATYPE *)malloc(10 * sizeof(DATATYPE));
}
return ppiHead;
}
void Delete_Det_Mem(DATATYPE **ppiHead,int iDetOrder)
{
int index = 0;
for(index = 0; index < iDetOrder; index ++)
{
free(*(ppiHead + index));
}
}
float Count_Det(DATATYPE **ppiHead,int iDetOrder)
{
int index;
float fResult = 0;
if (iDetOrder == 1)
{
return **ppiHead;
}
if (iDetOrder == 2)
{
fResult = *(*(ppiHead + 0)+0) * (*(*(ppiHead + 1)+1)) -
(*(*(ppiHead + 1)+0)) * (*(*(ppiHead + 0)+1));
return fResult;
}
for(index = 0; index < iDetOrder; index++)
{
if(*(*(ppiHead + 0) + index) != 0)
{
int x;
for(x = index; x < iDetOrder - 1; x++)
{
int y;
for(y = 1; y < iDetOrder; y++)
{
DATATYPE temp;
temp = *(*(ppiHead + y) + x);
*(*(ppiHead + y) + x) = *(*(ppiHead + y) + x + 1);
*(*(ppiHead + y) + x + 1) = temp;
}
}
if((index+1) % 2 == 1)
{
fResult += (*(*(ppiHead + 0) + index)) * Count_Det(ppiHead + 1,iDetOrder - 1);
}
else
{
fResult -= (*(*(ppiHead + 0) + index)) * Count_Det(ppiHead + 1,iDetOrder - 1);
}
for(x = iDetOrder - 1; x > index; x--)
{
int y;
for(y = 1; y < iDetOrder; y++)
{
DATATYPE temp;
temp = *(*(ppiHead + y) + x);
*(*(ppiHead + y) + x) = *(*(ppiHead + y) + x - 1);
*(*(ppiHead + y) + x - 1) = temp;
}
}
}
}
return fResult;
}