Hello, i have written this program, it is close to being finished... it should compile i think but im getting the following errors (lines might not match up)
Code:
ass.c:42: error: 'minordet' undeclared (first use in this function)
ass.c:42: error: (Each undeclared identifier is reported only once
ass.c:42: error: for each function it appears in.)
ass.c:42: error: too few arguments to function 'MinorDeterminant'
ass.c: At top level:
ass.c:55: error: conflicting types for 'MinorDeterminant'
ass.c:14: note: previous declaration of 'MinorDeterminant' was here
Here is the program:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
float MinorDeterminant(float minor[3][3], int i, int j);
int main(int argc, char* argv[])
{
FILE *input;
int i, j;
float matrix[3][3], determinant;
const char inp_fn[]="matrix.dat";
/* Open files */
input = fopen(inp_fn, "r");
/* Check the pointers to files are not NULL, also check matrix has correct number of elements... not done yet */
if( (input != (FILE*) NULL) )
{
{
printf("| ");
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
{
fscanf(input, "%f", &matrix[i][j]);
printf("%.4f ", matrix[i][j]);
if (j == 2 && i < 2)
printf("| \n |");
}
printf("|\n");
}
for(i=0, j=0; j<=2; j++)
{
determinant += (pow(-1, j)) * (matrix[i][j]) * MinorDeterminant(minordet);
printf("Determinant = %f", determinant);
}
fclose(input);
return(0);
}
else
{
printf("*** Could not open input file, or there are not 9 elements in the matrix ***\n");
exit(EXIT_FAILURE);
}
}
float MinorDeterminant(float matrix[3][3])
{
float minordet;
int i, j;
if (i==0 && j==0)
minordet = (matrix[1][1] * matrix[2][2]) - (matrix[2][1] * matrix[1][2]);
else if (i==0 && j==1)
minordet = (matrix[1][0] * matrix[2][2]) - (matrix[2][0] * matrix[1][2]);
else if (i==0 && j==2)
minordet = (matrix[1][0] * matrix[2][1]) - (matrix[2][0] * matrix[1][1]);
return(minordet);
}
Please help me fix the errors, thank you!