Thursday, 7 March 2019

CPP-EX8


WAP to create a matrix using M3=M1+M2                  
                                    
#include<iostream.h>
#include<conio.h>
class matrix
{
int m1[3][3];
public:
void input()
{
cout<<"Enter The Matix Element 3*3";
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cin>>m1[i][j];
}
}
}
matrix operator +( matrix mx)
{
matrix t;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
t.m1[i][j]=m1[i][j]+mx.m1[i][j];
}
}
return t;
}

void display()
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cout<<m1[i][j];
cout<<endl;
}}}
              
void main()
{
matrix m1,m2,m3;
clrscr();
m1.input();
m2.input();
m3=m1+m2;
m3.display();
getch();
}