-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatrixmultiply.c
71 lines (61 loc) · 1.19 KB
/
matrixmultiply.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
61
62
63
64
65
66
67
68
69
70
71
#include <stdio.h>
void main()
{
int n,m,i,j,k;
printf("Enter rows for first matrix");
scanf("%d", &n);
printf("Enter col for first matrix");
scanf("%d", &m);
int a[n][m];
printf("Enter the elements of first Matrix: ");
printf("\n");
for(i=0; i<n; i++)
{
for(j=0; j<m; j++)
{
scanf("%d", &a[i][j]);
}
}
// second matrix
int p,q;
printf("Enter rows for second matrix");
scanf("%d", &p);
printf("Enter col for second matrix");
scanf("%d", &q);
int b[p][q];
printf("Enter the elements of first Matrix: ");
printf("\n");
for(i=0; i<p; i++)
{
for(j=0; j<q; j++)
{
scanf("%d", &b[i][j]);
}
}
int c[n][q];
for(i=0; i<n; i++)
{
for(j=0; j<q; j++)
{
c[i][j] = 0;
}
}
for(i=0; i<n; i++)
{
for(j=0; j<q; j++)
{
for(k=0; k<p; k++)
{
c[i][j] += a[i][k]*b[k][j];
}
}
}
for(i=0; i<n; i++)
{
for(j=0; j<q; j++)
{
printf("%d", c[i][j]);
}
printf("\n");
}
}