FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Algorithm/Matrix-multiplication.cpp at main · vatsalya1102/Algorithm · GitHub
vatsalya1102
/
Algorithm
Public
forked from
heyimShivam/Algorithm
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Algorithm
/
Matrix-multiplication.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
63 lines (52 loc) · 1.5 KB
Breadcrumbs
Algorithm
/
Matrix-multiplication.cpp
Copy path
File metadata and controls
63 lines (52 loc) · 1.5 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
<
iostream
>
using
namespace
std
;
int
main
()
{
int
a[
10
][
10
], b[
10
][
10
], mult[
10
][
10
], r1, c1, r2, c2, i, j, k;
cout <<
"
Enter rows and columns for first matrix:
"
;
cin >> r1 >> c1;
cout <<
"
Enter rows and columns for second matrix:
"
;
cin >> r2 >> c2;
while
(c1!=r2)
{
cout <<
"
Error! column of first matrix not equal to row of second.
"
;
cout <<
"
Enter rows and columns for first matrix:
"
;
cin >> r1 >> c1;
cout <<
"
Enter rows and columns for second matrix:
"
;
cin >> r2 >> c2;
}
cout << endl <<
"
Enter elements of matrix 1:
"
<< endl;
for
(i =
0
; i < r1; ++i)
for
(j =
0
; j < c1; ++j)
{
cout <<
"
Enter element a
"
<< i +
1
<< j +
1
<<
"
:
"
;
cin >> a[i][j];
}
cout << endl <<
"
Enter elements of matrix 2:
"
<< endl;
for
(i =
0
; i < r2; ++i)
for
(j =
0
; j < c2; ++j)
{
cout <<
"
Enter element b
"
<< i +
1
<< j +
1
<<
"
:
"
;
cin >> b[i][j];
}
for
(i =
0
; i < r1; ++i)
for
(j =
0
; j < c2; ++j)
{
mult[i][j]=
0
;
}
for
(i =
0
; i < r1; ++i)
for
(j =
0
; j < c2; ++j)
for
(k =
0
; k < c1; ++k)
{
mult[i][j] += a[i][k] * b[k][j];
}
cout << endl <<
"
Output Matrix:
"
<< endl;
for
(i =
0
; i < r1; ++i)
for
(j =
0
; j < c2; ++j)
{
cout <<
"
"
<< mult[i][j];
if
(j == c2-
1
)
cout << endl;
}
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL