-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
47 lines (38 loc) · 1.25 KB
/
main.c
File metadata and controls
47 lines (38 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "libs/matrix_lib.h"
#include "libs/pivot.h"
#define DEBUG 0
int main(int argc, char* argv[]){
if(argc != 4){
printf("USAGE: %s FILENAME #ROWS #COLUMNS\n", argv[0]);
return -1;
}
int rows = atoi(*(argv+2));
int columns = atoi(*(argv+3));
int** matrix = readMatrix(*(argv+1), rows, columns);
if (matrix == NULL)
return -1;
printf("Input Matrix:\n");
displayMatrix(matrix, rows, columns);
int rowOffset = 0;
int columnOffset = 0;
while (checkZerosColumn(matrix, rows, rowOffset, columnOffset) && columnOffset <= rows)
columnOffset++;
int* pivot = getPivot(matrix, rows, rowOffset, columnOffset);
while (pivot) {
killColumn(matrix, rows, columns, rowOffset, columnOffset);
if (DEBUG) {
printf("after kill\n");
displayMatrix(matrix, rows, columns);
}
rowOffset++;
while (checkZerosColumn(matrix, rows, rowOffset, columnOffset) && columnOffset <= rows)
columnOffset++;
pivot = getPivot(matrix, rows, rowOffset, columnOffset);
}
printf("Output Matrix:\n");
displayMatrix(matrix, rows, columns);
for (int i = 0; i < rows; i++)
free(matrix[i]);
free(matrix);
return 0;
}