替我编写一个计算高阶行列式的代码
时间: 2023-04-01 15:01:18 浏览: 114
多阶行列式计算-java
好的,以下是一个计算高阶行列式的代码:
#include <stdio.h>
#define MAX_SIZE 10
int main()
{
int n, i, j, k, sign = 1;
double det = 1, temp;
double a[MAX_SIZE][MAX_SIZE];
printf("请输入行列式的阶数:");
scanf("%d", &n);
printf("请输入行列式的元素:\n");
for (i = ; i < n; i++)
{
for (j = ; j < n; j++)
{
scanf("%lf", &a[i][j]);
}
}
for (i = ; i < n - 1; i++)
{
for (j = i + 1; j < n; j++)
{
if (a[i][i] == )
{
for (k = i + 1; k < n; k++)
{
if (a[k][i] != )
{
for (j = ; j < n; j++)
{
temp = a[i][j];
a[i][j] = a[k][j];
a[k][j] = temp;
}
sign = -sign;
break;
}
}
}
if (a[i][i] == )
{
printf("行列式的值为\n");
return ;
}
temp = a[j][i] / a[i][i];
for (k = i; k < n; k++)
{
a[j][k] -= temp * a[i][k];
}
}
}
for (i = ; i < n; i++)
{
det *= a[i][i];
}
det *= sign;
printf("行列式的值为%.2lf\n", det);
return ;
}
阅读全文