**Introduction**

This program is of sum of matrices using 2d arrays. The program below is given. The program is extendable by using more numbers for matrix. Go enjoy the program. Lets begin……

**Program of sum of matrices**

#include<iostream.h>

#include<conio.h>

void main()

{

//clear the screen.

clrscr();

//declare variable type int

int a[3][3],b[3][3],i,j;

//Input the numbers of first matix

cout<<“First Matrix”<<endl;

for(i=0;i<3;i++)

{

for(j=0;j<3;j++)

{

cout<<“Enter number :”;

cin>>a[i][j];

}

}

//Input the numbers of second matix

cout<<“Second Matrix”<<endl;

for(i=0;i<3;i++)

{

for(j=0;j<3;j++)

{

cout<<“Enter number :”;

cin>>b[i][j];

}

}

//display the sum of matrices

cout<<“Sum is”<<endl;

for(i=0;i<3;i++)

{

for(j=0;j<3;j++)

{

cout<<a[i][j]+b[i][j]<<“\t”;

}

cout<<endl;

}

//get character

getch();

}

**Output**

First Matrix

Enter the number

1

Enter the number

2

Enter the number

3

Enter the number

4

Enter the number

5

Enter the number

6

Enter the number

7

Enter the number

8

Enter the number

9

Second Matrix

Enter the number

1

Enter the number

2

Enter the number

3

Enter the number

4

Enter the number

5

Enter the number

6

Enter the number

7

Enter the number

8

Enter the number

9

Sum is

2 4 6

8 10 12

14 16 18

//The above output looks great in c++. but blog does not show “\t” tabs. Sorry….

**How does it work**

- You enter the number.
- The number is saved in respective array for first matrix.
- The number is saved in respective array for second matrix.
- Then numbers are added and printed to form of matrix.

**Extending it**

The program can be extended by using more numbers and making the matrix more bigger. You can also do the same program to subtract the matrices. Go ahead. Extend it.

**Explanation.**

- Include ‘iostream.h’ and ‘conio.h’ files.
- Add void main.
- Start program by first clearing the screen.
- Declare the variables as int (name them as you want.)
- Add the cout and cin of array.
- Add for loop to print the sum of matrices.

**At the end**

You learnt creating the C++ program of Sum of matrices using 2d array. So now enjoy the program.

Please comment on the post and share it.

And like it if you liked.