print matrix cpp code example
Example 1: print matrix c++
#include
using namespace std;
int matrix[3][3];
int main()
{
// asigning values, I suppose this is done allready.
for(int x=0;x<3;x++)
{
for(int y=0;y<3;y++)
{
matrix[x][y]=1;
}
}
// showing the matrix on the screen
for(int x=0;x<3;x++) // loop 3 times for three lines
{
for(int y=0;y<3;y++) // loop for the three elements on the line
{
cout<
Example 2: how to print a 2d array in c++
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
cout << arr[i][j] << " ";
}
// Newline for new row
cout << endl;
}