#include <stdio.h>
#define tamanho 2
int main() {
double mat[tamanho][tamanho] = { {1, 4}, {7, 3} };
// double mat[tamanho][tamanho] = { {2, -4, 8}, {5, 4, 6}, {-3, 0, 2} };
// double mat[tamanho][tamanho] = { {1, 4, 7, 3}, {2, 6, -3, 0}, {2, 1, 3, 6}, {8, -2, 5, -1} };
// double mat[tamanho][tamanho] = { {1, 4, 7, 3, 2}, {6, -3, 0, 2, 1}, {3, 6, 8, -2, 5}, {-1, 0, 1, -7, -5}, {4, 6, -10.5, 0, -5} };
int i, j, pivo; // Índices para efetuar modificações na matriz.
int a, b; // Índices apenas para debugar a modificação da matriz.
printf("\nMatriz antes do cálculo\n"); for (a = 0; a < tamanho; a++) {
for (b = 0; b < tamanho; b++) {
}
}
printf("\nMatriz transposta é\n"); for (a = 0; a < tamanho; a++) {
for (b = 0; b < tamanho; b++) {
}
}
// Triangularizando a matriz.
for (pivo = tamanho - 1; pivo >= 0; pivo--) {
for (i = pivo - 1; i >= 0; i--) {
double mult = (-1) * mat[i][pivo] / mat[pivo][pivo];
for (j = tamanho - 1; j >= 0; j--) {
mat[i][j] += mult * mat[pivo][j];
} // Fim do for j.
printf("Matriz alterada com pivo=%d, i=%d\n", pivo
, i
); for (a = 0; a < tamanho; a++) {
for (b = 0; b < tamanho; b++) {
}
} // Fim do for a.
} // Fim do for i.
} // Fim do for pivo.
// Fim da triangularização da matriz. Pronto para o cálculo do determinante.
// Calculando determinante.
double det = 1;
for (i = 0; i < tamanho; i++) {
printf("mat[%d][%d] = %.2f\n", i
, i
, mat
[i
][i
]); det *= mat[i][i];
} // Fim do cálculo do determinante.
printf("\nDeterminante = %.2f\n", det
);
printf("\nMatriz após o cálculo\n"); for (a = 0; a < tamanho; a++) {
for (b = 0; b < tamanho; b++) {
}
} // Fim do for a.
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+IAoKI2RlZmluZSB0YW1hbmhvIDIKCmludCBtYWluKCkgewoKICAgIGRvdWJsZSBtYXRbdGFtYW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CiAgICAgICAgICAgIHByaW50ZigiJS4yZlx0IiwgbWF0W2JdW2FdKTsKICAgICAgICB9CiAgICAgICAgcHJpbnRmKCJcbiIpOwogICAgfQogICAgcHJpbnRmKCJcbiIpOwoKICAgIC8vIFRyaWFuZ3VsYXJpemFuZG8gYSBtYXRyaXouCiAgICBmb3IgKHBpdm8gPSB0YW1hbmhvIC0gMTsgcGl2byA+PSAwOyBwaXZvLS0pIHsKCiAgICAgICAgZm9yIChpID0gcGl2byAtIDE7IGkgPj0gMDsgaS0tKSB7CgogICAgICAgICAgICBkb3VibGUgbXVsdCA9ICgtMSkgKiBtYXRbaV1bcGl2b10gLyBtYXRbcGl2b11bcGl2b107CgogICAgICAgICAgICBmb3IgKGogPSB0YW1hbmhvIC0gMTsgaiA+PSAwOyBqLS0pIHsKICAgICAgICAgICAgICAgIG1hdFtpXVtqXSArPSBtdWx0ICogbWF0W3Bpdm9dW2pdOwogICAgICAgICAgICB9IC8vIEZpbSBkbyBmb3Igai4KCiAgICAgICAgICAgIHByaW50ZigiTWF0cml6IGFsdGVyYWRhIGNvbSBwaXZvPSVkLCBpPSVkXG4iLCBwaXZvLCBpKTsKICAgICAgICAgICAgZm9yIChhID0gMDsgYSA8IHRhbWFuaG87IGErKykgewogICAgICAgICAgICAgICAgZm9yIChiID0gMDsgYiA8IHRhbWFuaG87IGIrKykgewogICAgICAgICAgICAgICAgICAgIHByaW50ZigiJS4yZlx0IiwgbWF0W2FdW2JdKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHByaW50ZigiXG4iKTsKICAgICAgICAgICAgfSAvLyBGaW0gZG8gZm9yIGEuCgogICAgICAgIH0gLy8gRmltIGRvIGZvciBpLgogICAgfSAvLyBGaW0gZG8gZm9yIHBpdm8uCiAgICAvLyBGaW0gZGEgdHJpYW5ndWxhcml6YcOnw6NvIGRhIG1hdHJpei4gUHJvbnRvIHBhcmEgbyBjw6FsY3VsbyBkbyBkZXRlcm1pbmFudGUuCgogICAg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