forked from dimpeshpanwar/javabasicprograms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiply_matrices.java
41 lines (31 loc) · 975 Bytes
/
multiply_matrices.java
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
// Multiply Matrices
// Given two square Matrices A[][] and B[][]. Your task is to complete the function multiply which stores the multiplied matrices in a new matrix C[][].
// Example 1:
// Input:
// N = 2
// A[][] = {{7, 8}, {2 , 9}}
// B[][] = {{14, 5}, {5, 18}}
// Output:
// C[][] = {{138, 179}, {73, 172}}
// PROBLEM LINK: https://practice.geeksforgeeks.org/problems/multiply-matrices/1
// CODE
//--------------------------------------------------------
/*Complete the function below*/
class GfG
{
public static void multiply(int A[][], int B[][], int C[][], int N)
{
//add code here.
int c1=A[0].length;
int r2=B.length;
if(c1 != r2)
return;
for(int i=0;i<C.length;i++)
{
for(int j=0;j<C[0].length;j++){
for(int k=0;k<c1;k++)
C[i][j]+=A[i][k]*B[k][j];
}
}
}
}