forked from ravya1108/hactoberfest2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
customize_multiplication_matrix_finder.c
75 lines (56 loc) · 1.13 KB
/
customize_multiplication_matrix_finder.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
#include <stdio.h>
void run(int r1,int c1,int r2, int c2);
int main()
{
int r1,r2,c1,c2;
printf("1st size of matrix\nr1=");
scanf("%d",&r1);
printf("c1=");
scanf("%d",&c1);
printf("2nd size of matrix\n");
printf("r2=");
scanf("%d",&r2);
printf("c2=");
scanf("%d",&c2);
if(c1== r2 ){
run(r1,c1,r2,c2);
}else{
printf("invalid size: In multiplication of matrix c1 and r2 must be equal...");
}
return 0;
}
void run(int r1,int c1,int r2, int c2){
int a[r1][c1],b[r2][c2];
int mul[r1][c2];
printf("\n1st matrix\n\n");
for(int i=0;i<r1;i++){
for(int j=0;j<c1;j++){
printf("(%d, %d)= ",i+1,j+1);
scanf("%d",&a[i][j]);
}
printf("\n");
}
printf("\n2nd matrix\n\n");
for(int i=0;i<r2;i++){
for(int j=0;j<c2;j++){
printf("(%d, %d)= ",i+1,j+1);
scanf("%d",&b[i][j]);
}
printf("\n");
}
for(int i=0; i<r1;i++){
for(int j=0;j<c2;j++){
mul[i][j]=0;
for(int k=0;k<c1;k++){
mul[i][j]+=a[i][k]*b[k][j];
}
}
}
printf("Result is in %d*%d matrix\n\n\n",r1,c2);
for(int i=0; i<r1;i++){
for(int j=0;j<c2;j++){
printf("\t%d\t",mul[i][j]);
}
printf("\n");
}
}