forked from gnwgnw/tp_PREP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
65 lines (52 loc) · 1.55 KB
/
main.c
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "matrix.h"
#include <string.h>
#include <stdlib.h>
// Евгения Невтриносова
int main(int argc, char* argv[]) {
if (argc!=2){
printf("Error! Enter too much or too few values!\n");
return 1;
}
FILE *matrixFile;
if (((matrixFile = fopen(argv[1],"r"))==NULL)){
printf("Error! File is not open!\n");
return 0;
}
int num = 1000;
char *numWord = malloc(sizeof(*numWord) *64);
fgets(numWord, num, matrixFile);
if (!(*(numWord+1))){
printf("Error! File is empty or uncorrect!\n");
return 0;
}
free(numWord);
fclose(matrixFile);
matrixFile = fopen(argv[1],"r");
struct Matrix *myMatrix;
myMatrix = create_matrix_from_file(matrixFile);
double norma=0;
double max=1.7e-308;
for (int i=0; i<myMatrix->col; ++i){
for (int j=0; j<myMatrix->row; ++j){
norma += get_elem(myMatrix, j, i);
}
if (norma>max){
max = norma;
}
norma = 0;
}
printf("Матрица :\n");
for (int k=0; k<myMatrix->row; ++k){
for(int m=0; m<myMatrix->col; ++m){
printf("%.2f ", myMatrix->Matr[k][m]);
}
printf("\n");
}
if ((myMatrix->col!=0)&&(myMatrix->row!=0)) {
printf("В матрице %d строк(-и) и %d столбца(-ов) \n", get_rows(myMatrix), get_cols(myMatrix));
printf("Максимальная норма матрицы = %.3f\n", max);
}
fclose(matrixFile);
free_matrix(myMatrix);
return 0;
}