C++ PRACTICAL PROGRAMS

Class 12 Computer Science | ASSEB

Program to find the sum of two matrices

// Program to add two matrices of order 3×3

#include<iostream>

using namespace std;

int main( )

{

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

cout<<”Enter the first matrix”;

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

{ 

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

{        cin>>a[i][j]; }       

}

cout<<”Enter the second matrix”;

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

{ 

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

{        cin>>b[i][j]; }

}

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

{

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

{        s[i][j]=a[i][j]+b[i][j];          }

}

cout<<”Sum of two matrices is \n”;

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

{ 

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

{        cout<<s[i][j]<<” “; }

cout<<”\n”;

}

return 0;

}

Output

Enter the first matrix4

3

2

1

5

3

2

3

7

Enter the second matrix1

2

3

2

3

4

4

5

6

Sum of two matrices is

5 5 5

3 8 7

6 8 13

 

QUICK LINKS

Class 11

Class 12

Previous Year Paper

Practical Programs

Scroll to Top