# Source Code of Matrix Multiplication

If we have three matrices given as

double A[N * N];

double B[N * N];

double C[N * N];

Matrix multiplication can be calculated as:

for (int i = 0; i < N; ++i)

for (int j = 0; j < N; ++j)

for (int k = 0; k < N; ++k)

C[N * i + k] += A[N * i + j] * B[N * j + k];

In another way, if the matrices are given in two dimensional as

double A[N][N];

double B[N][N];

double C[N][N];

Matrix multiplication can be calculated as:

for (int i = 0; i < N; ++i)

for (int j = 0; j < N; ++j)

for (int k = 0; k < N; ++k)

C[i][k] += A[i][j] * B[j][k];

added 4 years ago