Multiply Matrices | Practice | GeeksforGeeks

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}}
 
Example 2:
Input: 
N = 2
A[][] = {{17, 4}, {17 , 16}}
B[][] = {{9, 2}, {7, 1}}

Output: 
C[][] = {{181, 38}, {265, 50}}
Constraints:
1 <=T<= 100
1 <= N <= 20
0
sumittripathi12 days ago
class GfG{     public static void multiply(int A[][], int B[][], int C[][], int N)       {          //add code here.                     for(int i=0;i<N;i++)           {               for(int j=0;j<N;j++)               {                   C[i][j]=0;                   for(int k=0;k<N;k++)                   {                       C[i][j]=C[i][j]+A[i][k]*B[k][j];                   }               }           }       }}
0
ds03245492 months ago
//Code
class GfG{     public static void multiply(int A[][], int B[][], int C[][], int N)       {         for(int i=0;i<N;i++){             for(int j=0;j<N;j++){                 C[i][j]=0;               for(int k=0;k<N;k++){                 C[i][j]+=A[i][k]*B[k][j];             }             }         }                 }}
0
swapniltayal4224 months ago
def multiply(A, B, C, n):  # Code here  for i in range(0,len(C)):      for j in range(0,len(C[0])):          for k in range(0,len(B)):              C[i][j]+=A[i][k]*B[k][j]  return C
 
+1
sohanr51720014 months ago
void multiply(int A[][100], int B[][100], int C[][100], int N){     //add code here.     for(int i=0; i<N; i++)     {         for(int j=0; j<N; j++)         {             C[i][j]=0;             for(int k =0; k<N; k++)             {                 C[i][j]+=A[i][k]*B[k][j];             }         }     }}
0
pankajkumarravi6 months ago
************************** I Have tried like this ***********
 
public static void multiply(int A[][], int B[][], int C[][], int N) {                for (int i=0;i<N;i++){                    for (int j=0;j<N;j++){                           C[i][j] =A[i][j]*B[i][j];                           System.out.print(C[i][j]+" ");                    }                    System.out.println();                }}
+1
pankajkumarravi6 months ago
Multiply Matrices does'nt have proper method signature.
0
018aryansharma6 months ago
this question should contain marks , as i had a really hard time solving it.
-4
mrshobhit7 months ago
Python 3:
Execution Time - 0.1 Sec
 
def multiply(A, B, C, n):
   # Code here
   for i in range(0,len(C)):
       for j in range(0,len(C[0])):
           for k in range(0,len(B)):
               C[i][j]+=A[i][k]*B[k][j]
   return C
0
vj9 months ago
vj
int sum;          for(int j=0;j<n;j++){ for(="" int="" k="0;k&lt;n;k++){" sum="0;" for(int="" l="0;l&lt;n;l++){" sum+="(A[j][l]*B[l][k]);" }="" c[j][k]="sum;" }="" }<="" code="">
0
martial10 months ago
martial
Use Divide-and-conquer algorithm
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as the final solution code.
You can view the solutions submitted by other users from the submission tab.