-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2D_Multiplication_matrix.c
58 lines (53 loc) · 1.13 KB
/
2D_Multiplication_matrix.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
#include<stdio.h>
int main()
{
int a[10][10],b[10][10],c[10][10];
int r1, c1, r2, c2,i,j,k,sum;
printf("Input Row & Column of first matrix: ");
scanf("%d%d",&r1,&c1);
printf("\nInput Row & Column of second matrix: ");
scanf("%d%d",&r2,&c2);
if(c1!=r2)
{
printf("\n Matrices are not multiplicable");
}
printf("\nEnter the Elements of Matrix A: \n");
for(i=0; i<r1; i++)
{
for(j=0; j<c1; j++)
{
scanf("%d\n",&a[i][j]);
}
}
printf("\nEnter the Elements of Matrix B: \n");
for(i=0; i<r2; i++)
{
for(j=0; j<c2; j++)
{
scanf("%d\n",&b[i][j]);
}
}
for(i=0; i<r1; i++)
{
for(j=0; j<c2; j++)
{
sum = 0;
for(k=0; k<c1; k++)
{
sum = sum + a[i][k]*b[j][k];
c[i][j] = sum;
}
}
}
printf("\n Product of Matrix:\n");
printf("\nMatrix C: ");
for(i=0; i<r1; i++)
{
for(j=0; j<c2; j++)
{
printf("%d\t",c[i][j]);
}
}
printf("\n");
return 0;
}