-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrixmath.c
More file actions
56 lines (50 loc) · 1.1 KB
/
Copy pathmatrixmath.c
File metadata and controls
56 lines (50 loc) · 1.1 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
#include <stdio.h>
#include <stdlib.h>
typedef struct matrixDef{
int m,n;
float **A;
} MD;
void create_matrix(MD* a,int rowSize,int colSize){
a->m = rowSize;
a->n = colSize;
a->A = (float**) malloc(sizeof(float*)*(a->m));
for(int i=0;i<(a->m);i++){
a->A[i] = (float*) malloc(sizeof(float)*(a->n));
}
}
void assign_value(MD *a){
float count = 1;
for(int i=0;i<(a->m);i++){
for (int j=0;j<(a->n);j++){
a->A[i][j] = count;
count += 1;
}
}
}
void print(MD *a){
for(int i=0;i<(a->m);i++){
for (int j=0;j<(a->n);j++){
printf("%0.2f ",a->A[i][j]);
}
printf("\n");
}
}
void multiply(MD *P,MD *A,MD *B){
for(int i=0;i<(A->m);i++){
for(int j=0;j<(B->n);j++){
int count = 0;
float res=0;
while(count < B->n){
res += A->A[i][count] * B->A[count][j];
count += 1;
}
P->A[i][j] = res;
}
}
}
void memfree(MD *a){
for(int i=0;i<(a->m);i++){
free(a->A[i]);
}
free(a->A);
}