Prints the even numbers from 1 to 20. It then prints the odd numbers from 1 to 20. - C++ Statement

C++ examples for Statement:for

Description

Prints the even numbers from 1 to 20. It then prints the odd numbers from 1 to 20.

Demo Code

#include <iostream>
using namespace std;
int main()//w w w  . ja v  a 2 s.co m
{
   int num;                       // The for loop variable
   cout << "Even numbers below 21\n";             // Title
   for (num=2; num<=20; num+=2)
   {
      cout << num << " ";
   }  // Prints every other number.
   cout << "\nOdd numbers below 20\n";   // A second title
   for (num=1; num<=20; num+=2)
   {
      cout << num << " ";
   }  // Prints every other number.
   return 0;
}

Result


Related Tutorials