# no se puede obtener el resultado exacto para Determinante

first of all im new on c.i try get a determinant of nxn matrix with this code

``````double Determinant(double *A, int N){
int i;
int j;
int k;
double y[100][100];
double x[100][100];
int sign = 1;
double result = 0;
int arrayRow;
int arrayColumn;

for(i = 0 ; i < N ; i++){
for(j = 0; j < N ;j++){
x[i][j] = A[(N*i)+j];}}

if(N == 2){
result =x[0][0]*x[1][1] - x[0][1]*x[1][0];
}
else
{
for(i = 0; i < N ; i++){
arrayRow = 0;
arrayColumn = 0;
for(j = 1 ;j < N; j++){
for( k = 0; k < N ; k++){
if(k == i){
continue;}
y[arrayRow][arrayColumn] =x[j][k];
arrayColumn++;
}
arrayColumn = 0;
arrayRow++;
}

result += sign*x[0][i]*Determinant(*y,N-1);
sign = -sign;}
}
printf("%d",result);
return result;
} /* end-Determinant */
``````

but it display something very unexpected number like -85899... . this is the test code and determinant doesn't return right result.

``````int main(){
double A[] = {5, 2, 4, 2, 4, 6, 1, 2, 8};
int a ;

if(Determinant(A, 3) == 80){
a = Determinant(A,3);
printf("%d",a);};
getchar();
} /* end-main */
``````

preguntado el 27 de noviembre de 13 a las 01:11

## 1 Respuestas

You have the wrong format specifier in printf.

Tratar: `printf("%f",a);` y `printf("%f",result);`

See printf format specifiers here http://www.cplusplus.com/reference/cstdio/printf/ (%d is for integers not doubles).

respondido 27 nov., 13:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.