Program for Matrix Addition


#include <iostream.h>
#include <conio.h>
void main ( )
{
       int i , j , add[3][3] ;
       int set1[3][3] = { {1,3,5},{7,9,11},{13,15,17} } ;
       int set2[3][3] = { {2,4,6},{8,10,12},{14,16,18} } ;
       cout<<"The first 3X3 matrix is :\n";
       for (i=0 ; i<3 ; i++)
       {
             for (j=0 ; j<3 ; j++)
             cout<<set1[i][j]<<"\t";
             cout<<"\n" ;
       }
       cout<<"\n" ;
       cout<<"The second 3X3 matrix is :\n";
       for (i=0 ; i<3 ; i++)
       {
             for (j=0 ; j<3 ; j++)
               cout<<set2[i][j]<<"\t";
             cout<<"\n" ;
        }
        cout<<"\n" ;
        for (i=0 ; i<3 ; i++)
        {
              for (j=0 ; j<3 ; j++)
              add[i][j] = set1[i][j] + set2[i][j] ;
        }
        cout<<"The resultant addition 3X3 matrix is :\n" ;
        for (i=0 ; i<3 ; i++)
        {
              for (j=0 ; j<3 ; j++)
                cout<<add[i][j]<<"\t";
              cout<<"\n" ;
        }
        cout<<"\n" ;
        getch ( ) ;
}

0 comments:

Post a Comment

 
 
 
 


Copyright © 2012 http://codeprecisely.blogspot.com. All rights reserved |Term of Use and Policies|