Hi everyone..

My desired output for this code is:

where n will be the value for the n x n matrix, which in this case is n=5.0 1 0 1 0

1 0 1 0 1

0 1 0 1 0

1 0 1 0 1

0 1 0 1 0

I have achieved to layout the matrix pattern but all the elements displayed are

0. How can I get it to display an alternate pattern of 0 and 1?

Thanks..

Code:#include <iostream> #include <vector> using namespace std; int main() { int n = 0; int i = 0, j = 1; vector<int> matrix; cout << "Enter a value for n where n >= 2: "; cin >> n; cout << endl; matrix.resize(n); if (n % 2 != 0) { for (i = 0; i < n; ++i) { for (j = 0; j < (n/2); ++j) cout << matrix[i] << " " << matrix[j] << " "; cout << matrix[i] << endl; } cout << endl; } else for (i = 0; i < n; ++i) { for (j = 0; j < (n/2); ++j) cout << matrix[i] << " " << matrix[j] << " "; cout << endl; } cout << endl; }