-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix_multiply.c
More file actions
69 lines (50 loc) · 1.26 KB
/
matrix_multiply.c
File metadata and controls
69 lines (50 loc) · 1.26 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
#include <stdio.h>
// void put_in_place(int rows, int cols, )
int main(void)
{
int m,n,p,i,j,k,sum;
//getting all dimension values from user
printf("For A, how many rows?\n");
scanf("%d", &m);
printf("How many columns?\n");
scanf("%d", &n);
printf("For B, how many columns?\n");
scanf("%d", &p);
//printing the values that scanf got from user
printf("%d%d%d\n", m, n, p);
double A[m][n], B[n][p], C[m][p];
printf("Enter all values in row order, starting with Matrix A\n");
//Putting values in A
for(i=0; i<m; i++)
for(j=0; j<n; j++)
scanf("%lf", &A[i][j]);
//printing all values of A
for(i=0; i<m; i++)
for(j=0; j<n; j++)
printf("%lf\n", A[i][j]);
printf("Please enter values for B in row order\n");
//Putting values in B
for(i=0; i<n; i++)
for(j=0; j<p; j++)
scanf("%lf", &B[i][j]);
//printing all values of B
for(i=0; i<n; i++)
for(j=0; j<p; j++)
printf("%lf\n", B[i][j]);
//matrix multiplication
for(i=0; i<m; i++)
for(j=0; j<p; j++)
{
sum=0;
for(k=0; k<n; k++)
sum+=A[i][k]*B[k][j];
C[i][j]=sum;
}
for(i=0; i<m; i++)
{
printf("\n");
for(j=0; j<p; j++)
printf("%lf ", C[i][j]);
}
printf("\n");
}