-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmatrix mul.cpp
94 lines (80 loc) · 1.48 KB
/
matrix mul.cpp
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
#include<stdio.h>
#include<conio.h>
int multi_arr(int [][10], int [][10], int [][10], int, int, int, int);
int main()
{
int a[10][10],b[10][10],multi[10][10];
int i,j,k,r1,c1,r2,c2,sum=0;
start:
printf("Enter No. of rows & column of matrice A:\n");
scanf("%d%d",&r1,&c1);
printf("Enter No. of rows & column of matrice B:\n");
scanf("%d%d",&r2,&c2);
if(c1!=r2)
{
printf("\nColumns of 1st matrice & Rows of 2nd matrice must be equal. \n");
printf("According to Rule of Multiplication.\n\n");
goto start;
}
printf("\nEnter the Elements in matrice A:\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\nEnter the Elements in matrice B:\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("Elements in matrice A:\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
printf("\nElements in matrice B:\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n");
}
multi_arr(a,b,multi,r1,c1,r2,c2);
return 0;
}
int multi_arr(int a[][10], int b[][10], int multi[][10],int r1,int c1,int r2,int c2)
{
int i,j,k,sum=0;
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
for(k=0;k<c1;k++)
{
sum=sum+a[i][k]*b[k][j];
}
multi[i][j]=sum;
sum=0;
}
}
printf("\nMultiplication of matrices A & B:\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
printf("%d\t",multi[i][j]);
}
printf("\n");
}
}