Skip to content

Commit 62cbbc6

Browse files
committed
feat: Multiply two 3x3 matrices using nested loops and store result in third matrix
🧠 Logic: - Matrix A is multiplied with Matrix B (identity matrix) using the standard matrix multiplication algorithm. - Uses three nested loops: - Outer two loops iterate over each cell in result matrix C. - Inner loop computes the dot product of row from A and column from B. - Prints matrix C using enhanced for-each loop. 📌 Result is same as Matrix A because Matrix B is an identity matrix. Signed-off-by: Somesh diwan <[email protected]>
1 parent 882ea48 commit 62cbbc6

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

Section9ArrayAB/Array IMP/MultiplyingTwoMatrices.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,20 @@ public static void main(String[] args) {
55

66
int C[][] = new int[3][3];
77

8-
for(int i=0;i<3;i++)
9-
{
10-
for(int j=0;j<3;j++)
11-
{
8+
for(int i=0;i<3;i++) {
9+
for(int j=0;j<3;j++) {
1210
C[i][j]=0;
13-
14-
for(int k =0; k<3;k++)
15-
{
11+
for(int k =0; k<3;k++) {
1612
C[i][j]=C[i][j]+A[i][k]*B[k][j];
1713
}
1814
}
1915
}
20-
for(int x[]: C)
21-
{
22-
for(int y:x)
23-
{
16+
17+
for(int x[]: C) {
18+
for(int y:x) {
2419
System.out.print(y+" ");
2520
}
2621
System.out.println();
2722
}
2823
}
29-
}
24+
}

0 commit comments

Comments
 (0)