Two Dimensional Array in C++ Part – 2
Master C++ with Real-time Projects and Kickstart Your Career Start Now!!
Program 1
// Two Dimensional Array
#include<iostream>
using namespace std;
int main()
{
system("cls");
int arr1[50][50],arr2[50][50],arr3[50][50],m,n;
int r,c;
cout<<"Enter value of row";
cin>>m;
cout<<"Enter value of column";
cin>>n;
// Read element in first matrics
cout<<"Enter elements in matrics:";
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
cin>>arr1[r][c];
}
}
cout<<"Elements of Matrics: \n ";
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
cout<<arr1[r][c]<<" ";
}
cout<<endl;
}
// Read element in second matrics
cout<<"Enter elements in matrics:";
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
cin>>arr2[r][c];
}
}
cout<<"Elements of Matrics: \n ";
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
cout<<arr2[r][c]<<" ";
}
cout<<endl;
}
// Addition of matrics
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
arr3[r][c]=arr1[r][c]+arr2[r][c];
}
cout<<endl;
}
cout<<"Addition is: : \n ";
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
cout<<arr3[r][c]<<" ";
}
cout<<endl;
}
}Program 2
// Two Dimensional Array
#include<iostream>
using namespace std;
int main()
{
system("cls");
int arr1[50][50],arr2[50][50],arr3[50][50],m,n;
int r,c;
cout<<"Enter value of row";
cin>>m;
cout<<"Enter value of column";
cin>>n;
// Read element in first matrics
cout<<"Enter elements in matrics:";
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
cin>>arr1[r][c];
}
}
cout<<"Elements of Matrics: \n ";
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
cout<<arr1[r][c]<<" ";
}
cout<<endl;
}
// Read element in second matrics
cout<<"Enter elements in matrics:";
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
cin>>arr2[r][c];
}
}
cout<<"Elements of Matrics: \n ";
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
cout<<arr2[r][c]<<" ";
}
cout<<endl;
}
// Multiplication of matrics
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
for(int k=0;k<m;k++)
{
arr3[r][c]=arr3[r][c]+(arr1[r][k]*arr2[k][c]);
}
}
cout<<endl;
}
cout<<"Multipilcation is: : \n ";
for(r=0;r<m;r++)
{
for(c=0;c<n;c++)
{
cout<<arr3[r][c]<<" ";
}
cout<<endl;
}
} Your 15 seconds will encourage us to work even harder
Please share your happy experience on Google

