-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadingMatrixFromFile.c
More file actions
81 lines (73 loc) · 1.32 KB
/
ReadingMatrixFromFile.c
File metadata and controls
81 lines (73 loc) · 1.32 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
int row, column, matrix1[3][3], matrix2[3][3], matrix3[3][3];
void getMatrix(){
printf("in getMatrix\n");
FILE *file1, *file2;
char *line, *number;
file1 = fopen("matrix.txt","r");
file2 = fopen("matrix1.txt","r");
row=0;
while(!feof(file1)) {
column = 0;
fscanf(file1, "%s", line);
number = strtok(line, ",");
while(number != NULL){
matrix1[row][column] = atoi(number);
column++;
number = strtok(NULL, ",");
}
printf("\n");
row++;
}
row=0;
while(!feof(file2)) {
column = 0;
fscanf(file2, "%s", line);
number = strtok(line, ",");
while(number != NULL){
matrix2[row][column] = atoi(number);
column++;
number = strtok(NULL, ",");
}
printf("\n");
row++;
}
}
void printMatrix(){
printf("in printmatrix\n");
int i, j;
for(i=0;i<3;i++){
for(j=0;j<3;j++){
printf("%d ",matrix3[i][j]);
}
printf("\n");
}
}
void multiplyMatrix() {
int sum=0;
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
for(int k=0;k<3;k++){
sum+=matrix1[i][k]*matrix2[k][j];
}
matrix3[i][j]=sum;
sum=0;
}
}
}
void main() {
printf("in main\n");
getMatrix();
printf("after getMatrix in main\n");
multiplyMatrix();
int i, j;
for(i=0;i<3;i++){
for(j=0;j<3;j++){
printf("%d ",matrix3[i][j]);
}
printf("\n");
}
}