Program for Addition of Multidimensional Array
#include<iostream>
#include<conio.h>
int main()
{
int a[5][5],b[5][5],c[5][5],i,j,m,n,p,q;
cout<<"Enter the Size of 1st Array:"<<endl;
cin>>m>>n;
cout<<"Enter the Size of 2st Array:"<<endl;
cin>>p>>q;
if(m==p && n==q)
{
cout<<"Enter the elements of 1st array:"<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
cin>>a[i][j];
}
cout<<"Enter the elements of 2nd array:"<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
cin>>b[i][j];
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
c[i][j]=a[i][j]+b[i][j];
}
cout<<" Matrix after Addition"<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
cout<<c[i][j]<<" ";
cout<<endl;
}
}
else
cout<<" Not Possible";
getch();
return 0;
}
No comments :
Post a Comment