-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrix Multiplication.c
220 lines (88 loc) · 2.67 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
int main (){
// Initialising 1st Matrix
system("clear");
int m1,n1,m2,n2;
printf("No of Rows of 1st Matrix : ");
scanf("%d",&m1);
printf("No of Columns of 1st Matrix : ");
scanf("%d",&n1);
// Initialising the 2nd Matrix
printf("No of Rows of 2nd Matrix : ");
scanf("%d",&m2);
printf("No of Columns of 2nd Matrix : ");
scanf("%d",&n2);
if (n1!=m2)
{
printf("Can't Compute ...\n");
// Checking n1=m2
}
else{
int matrix1[m1][n1];
int matrix2[m2][n2];
// Taking input of 1st Matrix
printf("\n ");
printf("Enter the 1st Matrix : \n\n");
for (int i=1;i<=m1;i++)
{
for (int j=1;j<=n1;j++)
{
printf("\ta[%d][%d] : ",i,j);
scanf("%d",&matrix1[i][j]);
}
}
// Taking input of 2nd Matrix
printf("\n ");
printf("Enter the 2nd Matrix : \n\n");
for (int i=1;i<=m2;i++)
{
for (int j=1;j<=n2;j++)
{
printf("\tb[%d][%d]",i,j);
scanf("%d",&matrix2[i][j]);
}
}
printf("\n");
// Printing 1st Matrix
for (int i=1;i<=m1;i++)
{
printf("\t");
printf("|");
for (int j=1;j<=n1;j++)
{
printf(" %d ",matrix1[i][j]);
}
printf("|");
printf("\n");
}
printf("\n\n");
// Printing 2nd Matrix
for (int i=1;i<=m2;i++)
{
printf("\t");
printf("|");
for (int j=1;j<=n2;j++)
{
printf(" %d ",matrix2[i][j]);
}
printf("|");
printf("\n");
}
int x=1,y=1,sum[m1][n2];
int product[x][y];
for (int k=1;k<=m1;k++)
{
for (int p=1;p<=n2;p++)
{
// product[k][p]=matrix1[k][p]*matrix2[p][k];
//um=sum+product[k][p];
// printf("%d",sum);
product[k][p]=matrix1[k][p]*matrix2[p][k];
sum[k][p]=sum[k][p]+product[k][p];
printf("%d\n",sum[k][p]);
}
}
} // Closing of else Statement
}