Friday 8 April 2016

WAP for addition of matrix.

#include<iostream.h>
#include<conio.h>
void main()
{
 int a[4][4],b[4][4],c[4][4],n,m,i,j;
 cout<<"\n enter size of rows :";
 cin>>n;
 cout<<"\n enter size of collumns  :";
 cin>>m;
 cout<<"\n enter element of 2d array :";
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
cin>>a[i][j];
}
}
 cout<<"\n first matrix \n\n\n:";
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
cout<<"\t"<<a[i][j];
}
cout<<"\n\n";
}
 cout<<"\n enter same size of rows :";
 cin>>n;
 cout<<"\n enter same size of collumns  :";
 cin>>m;
 cout<<"\n enter element of 2d array :";
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
cin>>b[i][j];
}
}
 cout<<"\n second matrix \n\n\n:";
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
cout<<"\t"<<b[i][j];
}
cout<<"\n\n";
}
for(i=1;i<=n;i++)
{
 for(j=1;j<=m;j++)
 {
  c[i][j]=a[i][j]+b[i][j];
 }
}
 cout<<"\n addition of matrix is \n\n\n:";
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
cout<<"\t"<<c[i][j];
}
cout<<"\n\n";
}
 getch();
 clrscr();
 }

No comments:

Post a Comment