forked from krishna14kant/Data-Structures-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix_Multiplication
More file actions
50 lines (40 loc) · 1021 Bytes
/
Matrix_Multiplication
File metadata and controls
50 lines (40 loc) · 1021 Bytes
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
#include <stdio.h>
int main()
{
int a,b,p,q,i,j,k,sum=0;
int one[10][10], two[10][10];
int multiply[10][10];
printf("Enter the number of rows and columns of first matrix\n");
scanf("%d%d",&a,&b);
printf("Enter the elements of first matrix\n");
for (i= 0;i< a;i++)
for (j= 0;j< b;j++)
scanf("%d",&one[i][j]);
printf("Enter number of rows and columns of second matrix\n");
scanf("%d%d", &p, &q);
if (b!= p)
printf("The multiplication isn't possible.\n");
else
{
printf("Enter elements of second matrix\n");
for (i= 0;i< p;i++)
for (j= 0;j< q;j++)
scanf("%d", &two[i][j]);
for (i= 0;i< a;i++) {
for (j= 0;j< q;j++) {
for (k = 0; k < p; k++) {
sum = sum + one[i][k]*two[k][j];
}
multiply[i][j] = sum;
sum = 0;
}
}
printf("Product of the matrices:\n");
for (i= 0;i< a;i++) {
for (j= 0;j< q; j++)
printf("%d\t", multiply[i][j]);
printf("\n");
}
}
return 0;
}