Saturday 5 July 2014

Matrix addition

Matrix addition
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,row,col,a[10][10],b[10][10],c[10][10];

cout<<"Enter the size of row and column of Matrices:";
cin>>row>>col;
cout<<"Enter the elements for Ist"<<row<<"x"<<col<<"matrix:";
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
cin>>a[i][j];
}
}
cout<<"Enter the elements for IInd"<<row<<"X"<<col<<"matrix:";
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
cin>>b[i][j];
}
}


for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}

cout<<"The sum of matrices is:";
for(i=0;i<row;i++)
{
cout<<"\n";
for(j=0;j<col;j++)
{
cout<<"\t"<<c[i][j];
}
}
getch();
}


No comments:

Post a Comment