### 1. Matrix Addition, Subtraction and Multiplication

1) Program a C++ function that prints out a given 5 x 5 matrix (void printMtrx(double mA[][SIZE_N], int size_n)). Use extended complete code to show the boundary of matrix.

2) Program a C++ function that calculates the addition of two 5 x 5 matrices, and returns the result as 2-dimensional parameter.

3) Program a C++ function that calculates the subtraction of two 5 x 5 matrices, and returns the result as 2-dimensional parameter.

4) Program a C++ function that calculates the multiplication of two 5 x 5 matrices, and returns the result as 2-dimensional parameter.

5) Calculate the addition, subtraction, multiplication of given matrices mA[][] and mB[][].

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344`` ``````Use following main() function. 4. main() function . . . . // insert necessary inludings here (e.g., library) #define SIZE_2D 5 #define SIZE_R 50000 . . . . // insert necessary definitions here void printMtrx(const int mX[], int size); void mtrxAdd(double mA[][SIZE_2D], double mB[][SIZE_2D], double mC[][SIZE_2D], int size_n); void mtrxSub(double mA[][SIZE_2D], double mB[][SIZE_2D], double mD[][SIZE_2D], int size_n); void mtrxMul(double mA[][SIZE_2D], double mB[][SIZE_2D], double mE[][SIZE_2D], int size_n); void main() { double mA[SIZE_2D][SIZE_2D] = { {1.0, 2.0, 3.0, 4.0, 5.0}, {2.0, 3.0, 4.0, 5.0, 1.0}, {3.0, 2.0, 5.0, 3.0, 2.0}, {4.0, 3.0, 2.0, 7.0, 2.0}, {5.0, 4.0, 3.0, 2.0, 9.0}, }; double mB[SIZE_2D][SIZE_2D] = { {1.0, 0.0, 0.0, 0.0, 0.0}, {0.0, 1.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 1.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 1.0, 0.0}, {0.0, 0.0, 0.0, 0.0, 1.0}, }; double mC[SIZE_2D][SIZE_2D], mD[SIZE_2D][SIZE_2D], mE[SIZE_2D][SIZE_2D]; int rn[SIZE_R]; int max, min; double avg, var, st_dev; cout << "Mtrx_A:" << endl; printMtrx(mA, SIZE_2D); cout << "Mtrx_B:" << endl; printMtrx(mB, SIZE_2D); mtrxAdd(mA, mB, mC, SIZE_2D); cout << "Mtrx_C = Mtrx_A + Mtrx_B:" << endl; printMtrx(mC, SIZE_2D); mtrxSub(mA, mB, mD, SIZE_2D); cout << "Mtrx_D = Mtrx_A - Mtrx_B:" << endl; printMtrx(mD, SIZE_2D); mtrxMul(mA, mB, mE, SIZE_2D); cout << "Mtrx_E = Mtrx_A x Mtrx_B:" << endl; printMtrx(mE, SIZE_2D);``````
Last edited on
Topic archived. No new replies allowed.