Reputation: 43
I don't understand why do I have a problem in this code
after doing some tests I understood that in this function determinant_V2
I can't even print Mat[0][0]
.
I don't understand why Mat
can't be used as a parameter
int main()
{
int n =0, pos=1;
float tmp=0;
printf("entrez la taille de la matrice : ");
scanf("%d",&n);
float** Mat = (float**) calloc(n,sizeof(float *));
for(int i = 0 ; i< n; i++){
Mat[i] = (float*) calloc(n,sizeof(float));
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
printf("\n entrer les valeurs de A[%d][%d] ",i+1,j+1);
scanf("%4f",Mat+i+j);
}
}
printf("delta general = %lf", determinant_V2(Mat,n));
return 0;
}
float** SousMatMinusLine(float** Mat, int taille ,int line){
float** sousMat = (float**) calloc(taille-1,sizeof(float *));
for(int i = 1 ; i< taille-1 ; i++){
if(i!=line){
sousMat[i] = (float*) calloc(taille-1,sizeof(float));
for(int j =1 ;j < taille-1; j++){
sousMat[i][j] = Mat[i][j];
}
}
}
//free(Mat);
return sousMat;
}
float determinant_V2(float ** Mat, int taille ){
int k = 1;
float det =0.0;
if(taille == 1){
return Mat[0][0];
}
for(int i =0 ; i<taille; i++){
float ** sous_Mat = SousMatMinusLine(Mat, taille,i);
det += determinant_V2(sous_Mat, taille -1 )*k ;
k *= -1;
}
return det;
}
Upvotes: 1
Views: 37
Reputation: 310910
This call of scanf
scanf("%4f",Mat+i+j);
is incorrect. You need to write
scanf("%4f", *( Mat + i )+j);
Upvotes: 2