#include <stdlib.h>
#include <stdio.h>
#include <math.h>
void print(double ** m, int N)
{
for(int i = 0; i < N; ++i)
{
for(int j = 0; j < N; ++j)
{
}
}
}
double GaussDet(double**m, int n)
{
double det = 1;
for(int i = 0; i < n; ++i)
{
double mx
= fabs(m
[i
][i
]); int idx = i;
for(int j = i+1; j < n; ++j)
if (mx
< fabs(m
[i
][j
])) mx
= fabs(m
[i
][idx
= j
]); if (idx != i)
{
for(int j = i; j < n; ++j)
{
double t = m[j][i];
m[j][i] = m[j][idx];
m[j][idx] = t;
}
det = -det;
}
for(int k = i+1; k < n; ++k)
{
double t = m[k][i]/m[i][i];
for(int j = i; j < n; ++j)
m[k][j] -= m[i][j]*t;
}
}
for(int i = 0; i < n; ++i) det *= m[i][i];
return det;
}
int main(int argc, const char * argv[])
{
#define N 5
double ** m
= malloc(N
*sizeof(double*)); for(int i
= 0; i
< N
; ++i
) m
[i
] = malloc(N
*sizeof(double));
for(int i = 0; i < N; ++i)
{
for(int j = 0; j < N; ++j)
{
}
}
m[0][0] = 0;
print(m,N);
printf("Det = %lf\n",GaussDet
(m
,N
));
}
I2luY2x1ZGUgPHN0ZGxpYi5oPgojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPG1hdGguaD4KCnZvaWQgcHJpbnQoZG91YmxlICoqIG0sIGludCBOKQp7CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgTjsgKytpKQogICAgewogICAgICAgIGZvcihpbnQgaiA9IDA7IGogPCBOOyArK2opCiAgICAgICAgewogICAgICAgICAgICBwcmludGYoIiUuMWxmICIsbVtpXVtqXSk7CiAgICAgICAgfQogICAgICAgIHB1dHMoIiIpOwogICAgfQogICAgcHV0cygiIik7Cn0KCgpkb3VibGUgR2F1c3NEZXQoZG91YmxlKiptLCBpbnQgbikKewogICAgZG91YmxlIGRldCA9IDE7CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgbjsgKytpKQogICAgewogICAgICAgIGRvdWJsZSBteCA9IGZhYnMobVtpXVtpXSk7CiAgICAgICAgaW50IGlkeCA9IGk7CiAgICAgICAgZm9yKGludCBqID0gaSsxOyBqIDwgbjsgKytqKQogICAgICAgICAgICBpZiAobXggPCBmYWJzKG1baV1bal0pKSBteCA9IGZhYnMobVtpXVtpZHggPSBqXSk7CiAgICAgICAgaWYgKGlkeCAhPSBpKQogICAgICAgIHsKICAgICAgICAgICAgZm9yKGludCBqID0gaTsgaiA8IG47ICsraikKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgZG91YmxlIHQgPSBtW2pdW2ldOwogICAgICAgICAgICAgICAgbVtqXVtpXSA9IG1bal1baWR4XTsKICAgICAgICAgICAgICAgIG1bal1baWR4XSA9IHQ7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZGV0ID0gLWRldDsKICAgICAgICB9CiAgICAgICAgZm9yKGludCBrID0gaSsxOyBrIDwgbjsgKytrKQogICAgICAgIHsKICAgICAgICAgICAgZG91YmxlIHQgPSBtW2tdW2ldL21baV1baV07CgogICAgICAgICAgICBmb3IoaW50IGogPSBpOyBqIDwgbjsgKytqKQogICAgICAgICAgICAgICAgbVtrXVtqXSAtPSBtW2ldW2pdKnQ7CiAgICAgICAgfQogICAgfQogICAgZm9yKGludCBpID0gMDsgaSA8IG47ICsraSkgZGV0ICo9IG1baV1baV07CiAgICByZXR1cm4gZGV0Owp9CgoKaW50IG1haW4oaW50IGFyZ2MsIGNvbnN0IGNoYXIgKiBhcmd2W10pCnsKICAgICNkZWZpbmUgIE4gIDUKICAgIGRvdWJsZSAqKiBtID0gbWFsbG9jKE4qc2l6ZW9mKGRvdWJsZSopKTsKICAgIGZvcihpbnQgaSA9IDA7IGkgPCBOOyArK2kpIG1baV0gPSBtYWxsb2MoTipzaXplb2YoZG91YmxlKSk7CgogICAgZm9yKGludCBpID0gMDsgaSA8IE47ICsraSkKICAgIHsKICAgICAgICBmb3IoaW50IGogPSAwOyBqIDwgTjsgKytqKQogICAgICAgIHsKICAgICAgICAgICAgbVtpXVtqXSA9IHJhbmQoKSUxMDsKICAgICAgICB9CiAgICB9CiAgICBtWzBdWzBdID0gMDsKICAgIHByaW50KG0sTik7CgogICAgcHJpbnRmKCJEZXQgPSAlbGZcbiIsR2F1c3NEZXQobSxOKSk7Cgp9Cg==