# 安徽大学（线性代数第一章详细答案）

#pragma warning(disable:4996)
#include <cstdio>
#include <cmath>

#define MAXN 100
#define zero(x) (fabs(x)<1e-10)

struct mat{
int n, m;
double data[MAXN][MAXN];
};
double det(const mat &a){
int i, j, k, sign = 0;
double b[MAXN][MAXN], ret = 1, t;
if (a.n != a.m) return 0;
for (i = 0; i<a.n; i++)
for (j = 0; j<a.m; j++)
b[i][j] = a.data[i][j];
for (i = 0; i<a.n; i++){//行标+列标
if (zero(b[i][i])){
for (j = i + 1; j<a.n; j++)//行标
if (!zero(b[j][i]))
break;
if (j == a.n) return 0;
for (k = i; k<a.n; k++)//列标
t = b[i][k], b[i][k] = b[j][k], b[j][k] = t;
sign++;
}
ret *= b[i][i];
for (k = i + 1; k<a.n; k++)//列标
b[i][k] /= b[i][i];
for (j = i + 1; j<a.n; j++)//行标
for (k = i + 1; k<a.n; k++)//列标
b[j][k] -= b[j][i] * b[i][k];
}
if (sign & 1) ret = -ret;
return ret;
}
int main(){
mat a;
int i, j, n;
while (scanf("%d", &n), n){
a.n = a.m = n;
for (i = 0; i<n; i++)
for (j = 0; j<n; j++)
scanf("%lf", &a.data[i][j]);
printf("det a : %.2lf\n", det(a));
}
return 0;
}


• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120