Skip to content

Matrix multiplication

Java nested loops

Flowchart (ISO 5807)

StartInput a, b, c, ni = 0, n − 1, 1j = 0, n − 1, 1c[i][j] = 0k = 0, n − 1, 1c[i][j] = c[i][j] + a[i][k]·b[k][j]EndFigure 1 — Matrix.multiply

Source code

Java
class Matrix {
    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] = c[i][j] + a[i][k] * b[k][j];
                }
            }
        }
    }
}

The editor opens with this code — change it and the chart redraws.

Language
Java
Constructs
nested loops
Topic
Loops
Formats
Word, Visio, draw.io, PDF, SVG

Related examples