hey guys i need help with iteration logic.
i need help with
1-prints out the integers between 2 and 1,048,576 (2^20) that are integer powers of 2.
2-prints out the integers between 1,048,576 down to 2 that are integer powers of 2
for 2nd question does this looks correct?
1 2 3 4 5
for (int i = 1048576; i >= 2; i >>= 1)
{
if ((i &(i - 1)) == 0)
cout << i << " ";
}
prints out the integers between 2 and 1,048,576 (2^20) that are integer powers of 2
and
prints out the integers between 1,048,576 down to 2 that are integer powers of 2
I am not going give you that determination. What do you think it is doing?
What happens when you run the original code?
What happens when you run the code with line 3 removed?
I am beginning to think that you found the code (on the internet or else where) and did not write it? So if you want more of my help, please explain what each part of the code you showed does in English (or your native language)? As a step for that, consider rewriting the for loop in its while loop equivalent. That is a good exercise under many circumstances.