Write a C++ program to take input in two Matrix in 2D Array and Print Them.
#include<iostream>
using namespace std;
int main()
{cout<<"[www.moznum.blogspot.com]"<<endl<<endl;
cout<<endl;
int row,col,row2,col2;
cout<<"Enter the number of rows of 1st Matrix: ";
cin >> row;
cout<<"Enter the number of Columns 1st Matrix: ";
cin>>col;
cout<<"Enter the number of rows of 2st Matrix: ";
cin >> row2;
cout<<"Enter the number of Columns 2st Matrix: ";
cin>>col2;
cout<<endl;
cout<<endl;
int array[row][col];
//taking input.
for(int index_row=0;index_row<row;index_row++) //here "index_row" is controlling the row of the matrix as well as contolling index of matrix.
{
for(int index_col=0;index_col<col;index_col++) //here "index_col" is controlling the Columns of the matrix as well as contolling index of matrix.
{
cout<<"Enter the "<< index_row+1<<index_col+1 <<" value of 1st Matrix : "; // Here I use "index_row+1" and "index_col+1" because i want to show user it is the 11 index or 12 etc, starting from 1, but in program "index_row" and "index_col" is actually starting from 0.
cin>>array[index_row][index_col];
}
}
cout<<endl;
int secondarray[row2][col2];
for(int index_row=0;index_row<row2;index_row++)
{
for(int index_col=0;index_col<col2;index_col++)
{
cout<<"Enter the "<< index_row+1<<index_col+1 <<" value of 2nd Matrix : "; // Here I use "index_row+1" and "index_col+1" because i want to show user it is the 11 index or 12 etc, starting from 1, but in program "index_row" and "index_col" is actually starting from 0.
cin>>secondarray[index_row][index_col];
}
}
cout<<endl<<endl;
// Printing Output
cout<<"Your 1st Matrix is : "<<endl;
for(int index_row=0;index_row<row;index_row++)
{
for(int index_col=0;index_col<col;index_col++)
{
cout<<array[index_row][index_col]<<" ";
}
cout<<endl; // this cout is used to move to send line after printing the 1st row.
}
cout<<endl<<endl;
cout<<"Your 2st Matrix is : "<<endl;
for(int index_row=0;index_row<row2;index_row++)
{
for(int index_col=0;index_col<col2;index_col++)
{
cout<<secondarray[index_row][index_col]<<" ";
}
cout<<endl; // this cout is used to move to send line after printing the 1st row.
}
}
You Can Also Search this topic by this:
C plus plus program to take input in Matrix in 2 Dimensional Array and print them.
How to take input in Matrix in 2 Dimensional (2D) array in C++ and print them.
Write a program in C++ to take input in 2 Matrix in 2D Array and print them.
No comments:
Post a Comment