-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultioftwomatrix.c
58 lines (51 loc) · 1.14 KB
/
multioftwomatrix.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 n,m,k,l;
printf("Enter the row of matrix:");
scanf("%d",&m);
printf("Enter the column of matrix:");
scanf("%d",&n);
printf("Enter the row of second matrix:");
scanf("%d",&k);
printf("Enter the column of second matrix:");
scanf("%d",&l);
int i,j;
int a[m][n], b[k][l],ans[m][l];
for(i=0;i<m;i++){
for(j=0;j<n;j++){
printf("Enter the elements of array a[%d][%d]:",i,j);
scanf("%d",&a[i][j]);
}
}
for(i=0;i<k;i++){
for(j=0;j<l;j++){
printf(" Enter the elements of array b[%d][%d]:",i,j);
scanf("%d",&b[i][j]);
}
}
for(i=0;i<m;i++){
for(j=0;j<l;j++){
ans[i][j]=0;
}
}
int s;
if(n==k) {
int x,y,z;
for(x=0; x<m; x++){
for(y=0; y<l; y++) {
for(z=0; z<n; z++) {
ans[x][y] += a[x][z] * b[z][y];
}
}
}
}
else {
printf("NOt possible");
}
for(i=0; i<m; i++) {
for(j=0; j<l; j++) {
printf("%d ",ans[i][j]);
}
printf("\n");
}
}