forked from keshavagarwal17/All-Cp-Algo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrix multiplication.c
60 lines (56 loc) · 1.14 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()
{
int m1,n1,m2,n2;
printf("Enter the number of rows of first matrix:");
scanf("%d",&m1);
printf("Enter the number of columns of first matrix:");
scanf("%d",&n1);
printf("Enter the number of rows of second matrix:");
scanf("%d",&m2);
printf("Enter the number of columns of second matrix:");
scanf("%d",&n2);
int a[m1][n1],b[m2][n2],c[m1][n2],i,j,k;
for(i=0;i<m1;i++)
{
for(j=0;j<n1;j++)
{
printf("a[%d][%d]:",i,j);
scanf("%d",&a[i][j]);
}
}
for(i=0;i<m2;i++)
{
for(j=0;j<n2;j++)
{
printf("b[%d][%d]:",i,j);
scanf("%d",&b[i][j]);
}
}
for(i=0;i<m1;i++)
{
for(j=0;j<n2;j++)
{
c[i][j]=0;
}
}
for(i=0;i<m1;i++)
{
for(j=0;j<n2;j++)
{
for(k=0;k<n1;k++)
{
c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
}
}
}
for(i=0;i<m1;i++)
{
for(j=0;j<n2;j++)
{
printf("%li ",c[i][j]);
}
printf("\n");
}
return 0;
}