thanks for the reply i tried changing that but now am not getting the right answer. its always giving me -1 (else condition answer). here is my function:
Code:
double det(double **M,int i,int j)
{
double det = 0;
if(i == j == 2)
{
det = M[i-2][j-2] * M[i-1][j-1] - M[i-1][j-2] * M[i-2][j-1];
return det;
}
else
return -1;
}
and my main:
Code:
int main()
{
int matsize,i=0,j=0;
double calcdet=0;
double Matrix [MAXSIZE][MAXSIZE]={{0}};
FILE* file = fopen("matrix.txt","r");
fscanf(file,"%d",&matsize);
for (i=0;i<matsize;i++)
{
for (j=0;j<matsize;j++)
{
fscanf(file,"%lf",&Matrix[i][j]);
}
j = 0;
}
fclose(file);
calcdet = det(&Matrix,2,2);
printf("%lf\n",calcdet);
system("PAUSE");
return 0;
}
I dont know what am doing wrong so if you can figure out my mistake i will be really thankful to you.