Addition of Two Matrices

In this program,two matrices are added using for loop.Firstly the elements of the rows and columns are specified then the elements are entered.The elements are added and stored in the third matrix as a result.

CODE

//to compute two matrices

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[3][3],b[3][3],row,column,i,j,sum[3][3];
cout<<" Enter the Number of Rows: ";
cin>>row;
cout<<" Enter the Number of Columns: ";
cin>>column;
cout<<" \n Enter First Matrix \n";
for(i=0;i<row;i++)
{
for(j=0;j<column;j++)
{
cout<<" Enter the no : ";
cin>>a[i][j];
}
}
cout<<"\n Enter Second Maxtrix \n";
for(i=0;i<row;i++)
{
for(j=0;j<column;j++)
{
cout<<" Enter the no : ";
cin>>b[i][j];
}
}
cout<<"\n Addition Matrix \n";
for(i=0;i<row;i++)
{
for(j=0;j<column;j++)
{
sum[i][j]=a[i][j]+b[i][j];
cout<<" "<<sum[i][j]<<" ";
}
cout<<endl;
}
getch();
}

OUTPUT

matrixadditions
Matrix Additions
(Visited 156 times, 1 visits today)
Share with Friends :
Written by:

Leave a Reply

Your email address will not be published. Required fields are marked *