Preface
Of course in c++ there are much more elegant solutions possible. This in case you implement a class Matrix (and Vector). But that was not your question.
Implementation trial according to your question
Here an implementation
completely untested, but I think because of some meaningfull namings more easy to understand and hopefully correct. Another thing: I'm assuming the matrices hold double values. Change the type according to your needs.
void MatrixMul(double A[], int ARows, int ACols,
double B[], int BRows, int BCols,
double C[])
{
if (ACols != BRows)
{
throw(*new Exception("Dimension Error"));
}
int CRows= ARows; int CCols= BCols;
for(int CRowIx= 0; CRowIx < CRows; CRowIx++)
{
for(int CColIx= 0; CColIx < CCols; CColIx++)
{
double Sum= 0.0; for(int k= 0; k < ACols; k++)
{
Sum+= B[k * BCols + CColIx] * A[CRowIx * ACols + k];
}
C[CRowIx * CCols + CColIx]= Sum;
}
}
}
Notes
Of course more index range checking are necessary to make it 'access violation" safe.
I hope it helps.