-3

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?

marmar
  • 13
  • 2

1 Answers1

2

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)
Pete Becker
  • 74,985
  • 8
  • 76
  • 165