forked from SoumyadeepMukherjee/Matrix_Manipulation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix_multiplication.c
60 lines (51 loc) · 1.52 KB
/
matrix_multiplication.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
#include<stdio.h>
int main(void)
{
int c, d, p, q, m, n, k, tot = 0;
int fst[10][10], sec[10][10], mul[10][10];
printf(" Please insert the number of rows and columns for first matrix \n ");
scanf("%d%d", &m, &n);
printf(" Insert your matrix elements : \n ");
for (c = 0; c < m; c++)
for (d = 0; d < n; d++)
scanf("%d", &fst[c][d]);
printf(" Please insert the number of rows and columns for second matrix\n");
scanf(" %d %d", &p, &q);
if (n != p)
printf(" Your given matrices cannot be multiplied with each other. \n ");
else
{
printf(" Insert your elements for second matrix \n ");
for (c = 0; c < p; c++)
for (d = 0; d < q; d++)
scanf("%d", &sec[c][d] );
for (c = 0; c < m; c++) {
for (d = 0; d < q; d++) {
for (k = 0; k < p; k++) {
tot = tot + fst[c][k] * sec[k][d];
}
mul[c][d] = tot;
tot = 0;
}
}
printf(" The first matrix is: \n ");
for (c = 0; c < m; c++) {
for (d = 0; d < n; d++)
printf("%d \t", fst[c][d] );
printf(" \n ");
}
printf(" The second matrix is: \n ");
for (c = 0; c < p; c++) {
for (d = 0; d < q; d++)
printf("%d \t", sec[c][d] );
printf(" \n ");
}
printf(" The result of matrix multiplication or product of the matrices is: \n ");
for (c = 0; c < m; c++) {
for (d = 0; d < q; d++)
printf("%d \t", mul[c][d] );
printf(" \n ");
}
}
return 0;
}