1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#include <iostream>
using namespace std;
constexpr int MAXROWS{ 8 }, MAXCOLS{ 8 };
int main()
{
int arr[MAXROWS][MAXCOLS]
{
{0, 1, 1, 1, 1, 1, 1, 0},
{0, 1, 0, 0, 0, 0, 1, 0},
{0, 1, 0, 0, 0, 0, 1, 0},
{0, 1, 0, 0, 0, 0, 1, 0},
{1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 0, 0, 0, 0, 0, 1},
{1, 1, 0, 0, 0, 0, 0, 1},
{1, 1, 0, 0, 0, 0, 0, 1}
};
int n = sizeof(arr); // <--- Not what you are expecting. Will return the size of the whole size of the array, i.e., number of bytes.
//if (arr == 0) // <--- Needs to be in 2 for loops to check each element of the array.
//{
// cout << " ";
//}
//else if (arr == 1)
//{
// cout << "#";
//}
for (int row = 0; row < MAXROWS; row++)
{
for (int col = 0; col < MAXCOLS; col++)
{
if (arr[row][col])
cout << "#";
else
cout << " ";
}
std::cout << '\n';
}
cout << '\n' << arr << '\n'; // <--- Will print the address of the array. You need 2 for loops to print each element of the array.
return 0; // <--- Not required, but makes a good break point for testing.
}
|