 Home >>Cpp Programs >CPP Program to print all Even and Odd numbers from 1 to N

# CPP Program to print all Even and Odd numbers from 1 to N

### C++ program to print all Even and Odd numbers from 1 to N

In this example, we will see a C++ program through which we can print all the Odd and even numbers between 1 to N.

STEPS:
• STEP 1:Get the integer number (N) as input.
• STEP 2:Run two separate loops from 1 to N.
• STEP 3:In the first loop, we will check the condition for the EVEN numbers and print them. In the second loop, we will check the condition for ODD numbers and print them.
• STEP 4:Find the remainder dividing by 2, if it is 0 then the number will be an EVEN number, else the number will be an ODD number.
Program:
``````
// C++ program to print all
// Even and Odd numbers from 1 to N
#include <iostream.h>
using namespace std;
// function : evenNumbers
// description: to print EVEN numbers only.
void evenNumbers(int n)
{
int i;
for (i = 1; i <= n; i++) {
//condition to check EVEN numbers
if (i % 2 == 0)
cout << i << " ";
}
cout << "\n";
}
// function : oddNumbers
// description: to print ODD numbers only.
void oddNumbers(int n)
{
int i;
for (i = 1; i <= n; i++) {
//condition to check ODD numbers
if (i % 2 != 0)
cout << i << " ";
}
cout << "\n";
}
// main code
int main()
{
int N;
// input the value of N
cout << "Enter the value of N (limit): ";
cin >> N;
cout << "EVEN numbers are...\n";
evenNumbers(N);
cout << "ODD numbers are...\n";
oddNumbers(N);
return 0;
}
```
```
Output:
Enter the value of N (limit): 100
EVEN numbers are...
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100
ODD numbers are...
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99