Monday, 18 May 2015

Write a program in c++ which read two matrix and then print a matrix which is addition of these two matrix.

Coding:- 

                    #include<iostream.h>

void main()

{
 int a[2][3],b[2][3],c[2][3];

 int i,j;

 cout<<"enter values in first matrix  \n";
 for(i=0;i<=1;i++)
 {

for(j=0;j<=2;j++)
cin>>a[i][j];


 }
cout<<"the matrix is : \n";

 for(i=0;i<=1;i++)
 {

for(j=0;j<=2;j++)
 cout<<"  "<<a[i][j];

 cout<<"\n";


 }
   
 cout<<"enter values in 2nd matrix  \n";
 for(i=0;i<=1;i++)
 {

for(j=0;j<=2;j++)
cin>>b[i][j];


 }
cout<<"the matrix is : \n";

 for(i=0;i<=1;i++)
 {

for(j=0;j<=2;j++)
 cout<<"  "<<b[i][j];

 cout<<"\n";


 }
           for(i=0;i<=1;i++)
 {

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

 c[i][j]=a[i][j]+b[i][j];

cout<<"\n";

}

         cout<<"the sum of two matrix is: = \n" ;

         for(i=0;i<=1;i++)
 {

for(j=0;j<=2;j++)
 cout<<"  "<<c[i][j];

 cout<<"\n";
} }


Output:-   

                                 

No comments:

Post a Comment