See also my comments. Assuming you Need to print "1" for odd numbers and "0" for even number you don't even Need an
if
.
This because
1 % 2 results in 1
2 % 2 results in 0
3 % 2 results in 1
4 % 2 results in 0
... and so on. Consult e.g. wiki for detailed Information about the Modulo Operator.
Version I Check Array values
Now I'm not familar with
cout
but something like this should do the job:
for(i= 0; i < n; i++)
{
cout << array[i] % 2;
}
[Edit0]
Version II Check index
for(i= 0; i < n; i++)
{
cout << i % 2;
}
[Edit1]
Version III Check index'
for(i= 0; i < n; i++)
{
cout << (i + 1) % 2;
}
Note: Keep in mind the comment of
Richard MacCutchan - Professional Profile[
^] : "Your main problem is that you never enter any values into the array."