Program -
#include<iostream.h>
#include<conio.h>
class mat
{
int
x[10][10],y[10][10],m,n,i,j;
public:
void readmat()
{
cout<<"\n
enter number of rows and columns of a matrix:"<<endl;
cin>>n>>m;
cout<<"\n
enter the element of matrix x:"<<endl;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
cin>>x[i][j];
}
}
cout<<"\n
entered matrix x is:\n";
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
cout<<"\t"<<x[i][j];
}
cout<<"\n";
}
cout<<"\n
enter the element of matrix y:"<<endl;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
cin>>y[i][j];
}
}
cout<<"\n
entered matrix y is:\n";
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
cout<<"\t"<<y[i][j];
}
cout<<"\n";
}
}
void addmat()
{
int add[10][10];
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
add[i][j]=x[i][j]+y[i][j];
}
}
}
void dispadd()
{
int add[10][10];
cout<<"\n
addition of two matrixes is \n: "<<endl;
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
cout<<"\t"<<add[i][j];
}
cout<<"\n";
}
}
};
void main()
{
mat obj;
clrscr();
obj.readmat();
obj.addmat();
obj.dispadd();
getch();
}
Output:
enter number of rows and columns of a matrix:
4 3
enter the element of matrix x:
2 3 4 5 6 7 8 9 6
5 4 3
entered matrix x is:
2 3 4
5
6 7
8
9 6
5
4 3
enter the element of matrix y:
6 7 8 5 4 3 7 8 9
5 7 6
entered matrix y is:
6
7 8
5
4 3
7 8
9
5
7 6
addition of two matrixes is
:
8
10 12
10
10 10
15
17 15
10
11 9
0 comments:
Post a Comment