-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix_multiplication.c
More file actions
73 lines (72 loc) · 1.75 KB
/
Matrix_multiplication.c
File metadata and controls
73 lines (72 loc) · 1.75 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
// Program to get product of two matrices
#include <stdio.h>
#include <conio.h>
void main()
{
int i, j, k, r1, r2, c1, c2, a[10][10], b[10][10], c[10][10];
printf("\nEnter row and column for first Matrix : ");
scanf("%d%d", &r1, &c1);
printf("\nEnter row and column for second Matrix : ");
scanf("%d%d", &r2, &c2);
if (r2 == c1)
{
printf("\nEnter Matrix A : ");
for (i = 0; i < r1; i++)
{
for (j = 0; j < c1; j++)
{
scanf("%d", &a[i][j]);
}
}
printf("\nMatrix A is :\n");
for (i = 0; i < r1; i++)
{
for (j = 0; j < c1; j++)
{
printf("%d\t", a[i][j]);
}
printf("\n");
}
printf("\nEnter Matrix B : ");
for (i = 0; i < r2; i++)
{
for (j = 0; j < c2; j++)
{
scanf("%d", &b[i][j]);
}
}
printf("\nMatrix B is :\n");
for (i = 0; i < r2; i++)
{
for (j = 0; j < c2; j++)
{
printf("%d\t", b[i][j]);
}
printf("\n");
}
for (i = 0; i < r1; i++)
{
for (j = 0; j < c2; j++)
{
c[i][j] = 0;
for (k = 0; k < c1; k++)
{
c[i][j] += a[i][k] * b[k][j];
}
}
}
printf("\nResultant Matrix is :\n");
for (i = 0; i < r1; i++)
{
for (j = 0; j < c2; j++)
{
printf("%d\t", c[i][j]);
}
printf("\n");
}
}
else
{
printf("Order not match. Multiplication not possible.");
}
}