import
java.util.Random;
import
java.util.Scanner;
public
class
GFG {
public
static
double
[][] multiplyVector(
double
[][] a,
double
[][] b,
int
n)
{
double
result[][] =
new
double
[n][
1
];
for
(
int
i =
0
; i < n; i++) {
for
(
int
j =
0
; j <
1
; j++) {
for
(
int
k =
0
; k < n; k++) {
result[i][j]
= result[i][j] + a[i][k] * b[i][j];
}
}
}
return
result;
}
public
static
void
main(String args[])
{
Scanner input =
new
Scanner(System.in);
System.out.println(
" Enter the dimensions of the matrix"
);
int
n = input.nextInt();
System.out.println(
"Enter the 1st matrix:"
);
double
a[][] =
new
double
[n][n];
for
(
int
i =
0
; i < n; i++) {
for
(
int
j =
0
; j < n; j++) {
a[i][j] = input.nextDouble();
}
}
System.out.println(
"Enter the 2nd matrix"
);
double
b[][] =
new
double
[n][n];
for
(
int
i =
0
; i < n; i++) {
for
(
int
j =
0
; j < n; j++) {
b[i][j] = input.nextDouble();
}
}
System.out.println(
"Enter the resultant matrix"
);
double
c[][] =
new
double
[n][n];
for
(
int
i =
0
; i < n; i++) {
for
(
int
j =
0
; j < n; j++) {
c[i][j] = input.nextDouble();
}
}
double
[][] r =
new
double
[n][
1
];
Random random =
new
Random();
for
(
int
i =
0
; i < n; i++) {
r[i][
0
] = random.nextInt(
2
);
}
double
br[][] =
new
double
[n][
1
];
double
cr[][] =
new
double
[n][
1
];
double
abr[][] =
new
double
[n][
1
];
br = multiplyVector(b, r, n);
cr = multiplyVector(c, r, n);
abr = multiplyVector(a, br, n);
boolean
flag =
true
;
for
(
int
i =
0
; i < n; i++) {
if
(abr[i][
0
] ==
0
)
continue
;
else
flag =
false
;
}
if
(flag ==
true
)
System.out.println(
"Yes,The matrix multiplication is correct"
);
else
System.out.println(
"No,The matrix multiplication is wrong"
);
input.close();
}
}