Hi guys, I have to make a program to print out the matrix from the file and its determinant. Here's the outline Im supposed to fill out:
Code:
#include
#define N 10
#define NMAX 4
double determinant2(double a[N][N]) ;
double determinant3(double a[N][N]) ;
double determinant4(double a[N][N]) ;
void read(double a[N][N], int n) ;
void print(double a[N][N], int n) ;
int count_inversions(int b[N], int n) ;
int
main(void)
{
double a[N][N] ;
double determinant ;
int n ;
/*
Get n, the size of the square array
*/
/*
Read the n by n array and then print it.
*/
/*
Find and print the determinant of the matrix
*/
}
And heres what I got so far:
Code:
#include<stdio.h>
#include<stdlib.h>
#define N 10
#define NMAX 4
void read(double a[N][N], int n)
{
int i,j;
for (i=0; i<n; i++)
{
for (j=0;j<n;j++)
scanf("%lf",&a[i][j]);
}
}
void print(double a[N][N], int n)
{
int i,j;
for (i=0; i<n; i++)
{
for (j=0;j<n;j++)
printf("%.2lf\n", a[i][j]);
}
}
main ()
{
int n;
FILE *inp;
inp = fopen("matrix.txt", "r");
double a[N][N];
fscanf(inp, "%d", &n);
printf("The size of matrix is %d\n", n);
read(a, n);
print(a, n);
}
and the sample of the input file must be in the following format:
4
1 2 5 6
8 5 6 7
4 5 9 8
2 8 4 1
where the first element (4) indicates the size of square matrix(4x4)
As you can see Im trying to read the matrix from the input file and print it out on the screen, but the errors Im getting are:
assi2-.c: In function `main':
assi2-.c:42: parse error before `double'
assi2-.c:47: `a' undeclared (first use in this function)
If anyone can help me out with this, it be greatly appreciated. Thank you for looking.