Hi laserlight..
Thanks for the quick response. This is what I came up with. It works the way I wanted it to but do I really need to use a matrix for this? I guess, what I was trying to say is what is the most efficient way to write this program? I will greatly apreciate your opinion.
Thanks again..
Code:
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n = 0;
int bit0 = 0, bit1 = 1;
int i = 0, j = 0;
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/2); ++i)
{
for (j = 0; j < (n/2); ++j)
cout << bit0 << " " << bit1 << " ";
cout << bit0 << endl;
for (j = 0; j < (n/2); ++j)
cout << bit1 << " " << bit0 << " ";
cout << bit1 << endl;
}
for (i = 0; i < (n/2); ++i)
{
cout << bit0 << " " << bit1 << " ";
}
cout << bit0 << endl;
}
else
for (i = 0; i < (n/2); ++i)
{
for (j = 0; j < (n/2); ++j)
cout << bit0 << " " << bit1 << " ";
cout << endl;
for (j = 0; j < (n/2); ++j)
cout << bit1 << " " << bit0 << " ";
cout << endl;
}
cout << endl;
}