# Source Code of Matrix Multiplication

If three matrices are given as

double A[N * N];

double B[N * N];

double C[N * N];

and the values of A[...] and B[...] are initialized, the matrix multiplication of **A x B** 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 as two dimensional matrix form such that

double A[N][N];

double B[N][N];

double C[N][N];

the matrix multiplication of **A x B** 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 10 years ago