Print matrix or two dimension array in C++
Simple C++ program to print matrix. To print matrix, we use two for loop. First for loop is for rows in matrix and second for loop is for columns in matrix.
/* C++ Program to print matrix */ #include<iostream> using namespace std; int main() { int row,column; cout<<"Enter rows in matrix: "; cin>>row; cout<<"Enter columns in matrix: "; cin>>column; int matrix[row][column]; cout<<"Enter matrix elements: "<<endl; for(int i=0;i<row;i++) { for(int j=0;j<column;j++) { cin>>matrix[i][j]; } } cout<<"Matrix is: "<<endl; for(int i=0;i<row;i++) { for(int j=0;j<column;j++) { cout<<matrix[i][j]<<" "; } cout<<endl; } return 0; }