-
Notifications
You must be signed in to change notification settings - Fork 1
/
multiplyMatrix.c
49 lines (49 loc) · 1.23 KB
/
multiplyMatrix.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
//
// Created by sids on 29/10/18.
//
#include <stdio.h>
int matrix(int i, int j,int k);
int main(){
int i,j,k;
printf("Enter the rows in the first 2D array.\n");
scanf("%d",&i);
printf("Enter the columns in the first and rows in the second 2D array.\n");
scanf("%d",&j);
printf("Enter the columns in the second 2D array.\n");
scanf("%d",&k);
matrix(i,j,k);
return 0;
}
int matrix(int i,int j,int k){
int first[i][j],second[j][k],multiplied[i][k],m,n,sum,val,o;
printf("Please enter the elements in the first matrix.\n");
for(m=0;m<i;m++){
for(n=0;n<j;n++){
scanf("%d",&first[m][n]);
}
}
printf("Please enter the elements in the second matrix.\n");
for(m=0;m<j;m++){
for(n=0;n<k;n++){
scanf("%d",&second[m][n]);
}
}
for(m=0;m<i;m++){
for(n=0;n<k;n++){
sum=0;
for(o=0;o<j;o++){
val=first[m][n]*second[o][n];
sum=val+sum;
}
multiplied[m][n]=sum;
}
}
printf("The resultant matrix is: \n");
for(m=0;m<i;m++){
for(n=0;n<k;n++){
printf("%d ",multiplied[m][n]);
}
printf("\n");
}
return 0;
}