This c program add two matrices i.e. compute the sum of two matrices and then print it. Firstly user will be asked to enter the order of matrix ( number of rows and columns ) and then two matrices. For example if the user entered order as 2, 2 i.e. two rows and two columns and matrices as

Algorithm:

For example: Suppose two matrix A and B of size of 2 X 3 is as follow:

First Matrix :

2 2

2 4

Second matrix :

4 5

-1 5

then output of the program ( sum of First and Second matrix ) will be

6 7

1 9

Algorithm:

Rule: Addition of two matrixes is only possible if both matrixes are of same size.

Suppose two matrixesAandBis of same sizem X n

Sum of two marixes is defined as

(A + B)ij = Aij + Bij

Where 1 ≤ i ≤ m and 1 ≤ j ≤ n

For example: Suppose two matrix A and B of size of 2 X 3 is as follow:

#### Example: C++ program to add two matrix using multi-dimensional arrays

#### Output

Enter number of rows (between 1 and 20): 2

Enter number of columns (between 1 and 20): 2

Enter elements of 1st matrix:

Enter element a11 : 2

Enter element a12 : 4

Enter element a21 : 6

Enter element a22 : 2

Enter elements of 2nd matrix:

Enter element b11 : 2

Enter element b12 : 5

Enter element b21 : 9

Enter element b22 : 7

Sum of two matrix is:

4 9

15 9

## Post a Comment