//Add the matrices and display
Console::WriteLine("Sample Matrix Addition");
MatrixAdd(M3,M1,M2);
PrintMatrix(M3); //show M3 on the screen so we can test and see if addition worked;
}
// Here is the function that:
//calculate C=A+B, where A and B are given square matrices of size 3x3
void MatrixAdd(double C[3][3], double A[3][3], double B[3][3])
{
for (int row=0; row < 3; ++row)
{
for (int col=0; col < 3; ++col)
{
C[row][col] = A[row][col]+B[row][col];
}
}
}
// Display a matrix on the screen
void PrintMatrix(double M[3][3])
{
for (int row=0; row < 3; ++row)
{
for (int col=0; col < 3; ++col)
{
printf("%f, ",M[row][col]);
}
printf("\n");
}
}