Image

Programs - C++ - Matrix

Program:


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


:"
;
for(i=1;i<=n;i++)
 {
  for(j=1;j<=m;j++)
  {
  cout<<" "<<a[i][j];
  }
  cout<<"

"
;
 }
cout<<"
enter same size of rows  :"
;
cin>>n;
cout<<"
enter same size of collumns :"
;
cin>>m;
cout<<"
enter element of 2d array :"
;
for(i=1;i<=n;i++)
 {
  for(j=1;j<=m;j++)
  {
  cin>>b[i][j];
  }
 }
cout<<"
second matrix


:"
;
for(i=1;i<=n;i++)
 {
  for(j=1;j<=m;j++)
  {
  cout<<" "<<b[i][j];
  }
  cout<<"

"
;
 }
for(i=1;i<=n;i++)
 {
  for(j=1;j<=m;j++)
  {
   c[i][j]=a[i][j]+b[i][j];
  }
 }
cout<<"
addition of matrix is


:"
;
for(i=1;i<=n;i++)
 {
  for(j=1;j<=m;j++)
  {
  cout<<" "<<c[i][j];
  }
  cout<<"

"
;
 }
getch();
clrscr();
}