How do I print only the even integers using a loop?
so far I have:
for (int i = 100; i > 0; i--)
{
cout << i << ", ";
}
which prints all the numbers, even and odd. How do I print just the even numbers?
CodePudding user response:
Sigh. All the comments (and the close vote) seem hung up on checking whether an integer is even. That's not needed; instead of skipping odd values, don't generate them in the first place:
for (int i = 100; i > 0; i-=2)