#include <stdio.h> #include <math.h> void zerar(int n,int m[][n]) { int i, j; for (i=0; i<n; i++) { for (j=0; j<n; j++) { m[i][j] = 0; } } } void printm(int n, int matriz[][n]) { int i,j; for (i=0; i<n; i++) { for (j=0; j<n; j++) { } } } int det(int n, int matriz[][n]) { int i, j, k, x, y, soma=0, aux[n-1][n-1]; zerar(n, aux); if (n < 1) {} else if (n == 1) { return matriz[0][0]; } else if (n == 2) { soma = (matriz[0][0] * matriz[1][1]) - (matriz[0][1] * matriz[1][0]); return soma; } else { for (i=0; i<n; i++) { for (j=1, x=0; j<n; j++) { for (k=0, y=0; k<n; k++) { if (k == i) { continue; } else { printm(n-1, aux); aux[x][y] = matriz[j][k]; y++; } } x++; } } return soma; } } int main() { int m[3][3] = {{4, 3, 2}, {1, 4, 5}, {2, 1, 2}}; det(3, m); printm(3, m); }
Standard input is empty
0 0 0 0 x=0, y=0, j=1, k=1, i=0 4 0 0 0 x=0, y=1, j=1, k=2, i=0 4 5 0 0 x=1, y=0, j=2, k=1, i=0 4 5 1 0 x=1, y=1, j=2, k=2, i=0 4 5 1 2 x=0, y=0, j=1, k=0, i=1 1 5 1 2 x=0, y=1, j=1, k=2, i=1 1 5 1 2 x=1, y=0, j=2, k=0, i=1 1 5 2 2 x=1, y=1, j=2, k=2, i=1 1 5 2 2 x=0, y=0, j=1, k=0, i=2 1 5 2 2 x=0, y=1, j=1, k=1, i=2 1 4 2 2 x=1, y=0, j=2, k=0, i=2 1 4 2 2 x=1, y=1, j=2, k=1, i=2 0 0 0 0 x=0, y=0, j=1, k=1, i=0 4 0 0 0 x=0, y=1, j=1, k=2, i=0 4 5 0 0 x=1, y=0, j=2, k=1, i=0 4 5 1 0 x=1, y=1, j=2, k=2, i=0 4 5 1 2 x=0, y=0, j=1, k=0, i=1 1 5 1 2 x=0, y=1, j=1, k=2, i=1 1 5 1 2 x=1, y=0, j=2, k=0, i=1 1 5 2 2 x=1, y=1, j=2, k=2, i=1 1 5 2 2 x=0, y=0, j=1, k=0, i=2 1 5 2 2 x=0, y=1, j=1, k=1, i=2 1 4 2 2 x=1, y=0, j=2, k=0, i=2 1 4 2 2 x=1, y=1, j=2, k=1, i=2 22 4 3 2 1 4 5 2 1 2