Given a number N, the task is to print N even numbers and N odd numbers from 1.

**Examples:**

Input:N = 5Output:Even: 2 4 6 8 10 Odd: 1 3 5 7 9Input:N = 3Output:Even: 2 4 6 Odd: 1 3 5

**Approach:**

**For Even numbers:**- Even number are numbers that are divisible by 2.
- To print even numbers from 1 to N, traverse each number from 1.
- Check if these numbers are divisible by 2.
- If true, print that number.

**For Odd numbers:**- Odd number are numbers that are not divisible by 2.
- To print Odd numbers from 1 to N, traverse each number from 1.
- Check if these numbers are not divisible by 2.
- If true, print that number.

- Program to print Sum of even and odd elements in an array
- Program to print product of even and odd indexed elements in an Array
- Python program to count Even and Odd numbers in a List
- Python program to print all odd numbers in a range
- Python program to print all even numbers in a range
- Generate an array of given size with equal count and sum of odd and even numbers
- Print "Even" or "Odd" without using conditional statement
- Frequencies of even and odd numbers in a matrix
- Count Odd and Even numbers in a range from L to R
- Largest Even and Odd N-digit numbers in Hexadecimal Number System
- Python program to print odd numbers in a List
- Python program to print even numbers in a list
- Represent N as sum of K even or K odd numbers with repetitions allowed
- Sum of even numbers at even position
- Program to check if a number is Positive, Negative, Odd, Even, Zero
- C program to check whether a given number is even or odd
- Even digits Sum and Odd digits sum divisible by 4 and 3 respectively
- Program to print all the numbers divisible by 3 and 5 for a given number
- Count even and odd digits in an Integer
- Count number of even and odd elements in an array

Below is the implementation of the above approach:

`// C++ program to print all Even ` `// and Odd numbers from 1 to N ` ` ` `#include <bits/stdc++.h> ` `using` `namespace` `std; ` ` ` `// Function to print even numbers ` `void` `printEvenNumbers(` `int` `N) ` `{ ` ` ` ` ` `cout << ` `"Even: "` `; ` ` ` `for` `(` `int` `i = 1; i <= 2 * N; i++) { ` ` ` ` ` `// Numbers that are divisible by 2 ` ` ` `if` `(i % 2 == 0) ` ` ` `cout << i << ` `" "` `; ` ` ` `} ` `} ` ` ` `// Function to print odd numbers ` `void` `printOddNumbers(` `int` `N) ` `{ ` ` ` ` ` `cout << ` `"\nOdd: "` `; ` ` ` `for` `(` `int` `i = 1; i <= 2 * N; i++) { ` ` ` ` ` `// Numbers that are not divisible by 2 ` ` ` `if` `(i % 2 != 0) ` ` ` `cout << i << ` `" "` `; ` ` ` `} ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` ` ` `int` `N = 5; ` ` ` ` ` `printEvenNumbers(N); ` ` ` `printOddNumbers(N); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

**Output:**

Even: 2 4 6 8 10 Odd: 1 3 5 7 9

Rated as one of the most sought after skills in the industry, own the basics of coding with our **C++ STL** Course and master the very concepts by intense problem-solving.

## Recommended Posts:

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.