Addition of two matrix using class
Code of Addition of matrix using Class
#include<iostream.h>
#include<conio.h>
class add
{
int row, clm, a[10][10], b[10][10], sum[10][10]
void read()
{
cout<<"Enter the no. of rows";
cin>>row;
cout<<"Enter the no. of clms";
cin>>clm;
cout<<"Enter the first matrics \n";
for(int i=0;i<row;i++)
{
for(int j=0;j<clm;j++)
{
cin>>a[i][j];
}
cout<<end1;
}
cout<<"Enter the second matrix \n";
for(int i=0;i<row;i++)
{
for(int j=0;j<clm;j++)
{
cin>>b[i][j];
}
cout<<end1;
}
}
void sumd()
{
for(int i=0;i<row;i++)
{
for(int j=0;j<clm;j++)
{
sum[i][j]=a[i][j]+b[i][j];
}
}
cout<<"The result matrix \n";
for(int i=0;i<row;i++)
{
for(int j=0;j<clm;j++)
{
cin>>sum[i][j];
}
cout<<end1;
}
}
}b;
void main()
{
clrscr();
b.read();
b.sumd();
getch();
}
cout<<"Enter the no. of rows";
cin>>row;
cout<<"Enter the no. of clms";
cin>>clm;
cout<<"Enter the first matrics \n";
for(int i=0;i<row;i++)
{
for(int j=0;j<clm;j++)
{
cin>>a[i][j];
}
cout<<end1;
}
cout<<"Enter the second matrix \n";
for(int i=0;i<row;i++)
{
for(int j=0;j<clm;j++)
{
cin>>b[i][j];
}
cout<<end1;
}
}
void sumd()
{
for(int i=0;i<row;i++)
{
for(int j=0;j<clm;j++)
{
sum[i][j]=a[i][j]+b[i][j];
}
}
cout<<"The result matrix \n";
for(int i=0;i<row;i++)
{
for(int j=0;j<clm;j++)
{
cin>>sum[i][j];
}
cout<<end1;
}
}
}b;
void main()
{
clrscr();
b.read();
b.sumd();
getch();
}
Output:-
Enter the no. of rows 2
Enter the no. of clms 2
Enter the first matrix
1
2
3
4
Enter the second matrix
5
6
7
8
The result matrix
6 8
10 12
Comments
Post a Comment