行列式c语言编程,用C语言编写计算任意阶行列式的程序

#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;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值