# C++ program to Print Even Numbers

Write a C++ Program to Print Even Numbers from 0 to given value. This C++ program allows you to enter any integer number. Next, we used the for loop to iterate numbers from 1 to that number. Within the loop, we used the If statement to check whether i % 2 equal to 0. If true, print the i value as the even number.

```#include<iostream>
using namespace std;

int main()
{
int number;

cout << "\nPlease Enter Maximum limit Value to print Even Numbers =  ";
cin >> number;

cout << "\nList of Even Numbers from 1 to " << number << " are\n";
for(int i = 1; i <= number; i++)
{
if ( i % 2 == 0 )
{
cout << i <<" ";
}
}

return 0;
}```
``````Please Enter Maximum limit Value to print Even Numbers =  15

List of Even Numbers from 1 to 15 are
2 4 6 8 10 12 14 ``````

In this C++ Program, we alter the for loop (for(int i = 2; i <= number; i= i + 2)) to remove the If statement to return even Numbers. Here, we incremented the i value to 2 (instead of 1). So that every number from 2 with an increment of two will be an even number.

```#include<iostream>
using namespace std;

int main()
{
int number;

cout << "\nPlease Enter Maximum limit Value to print Even Numbers =  ";
cin >> number;

cout << "\nList of Even Numbers from 1 to " << number << " are\n";
for(int i = 2; i <= number; i= i + 2)
{
cout << i <<" ";
}

return 0;
}```
``````Please Enter Maximum limit Value to print Even Numbers =  25

List of Even Numbers from 1 to 25 are
2 4 6 8 10 12 14 16 18 20 22 24 ``````

## C++ Program to Print Even Numbers using a While Loop

```#include<iostream>
using namespace std;

int main()
{
int number, i = 2;

cout << "\nPlease Enter Maximum limit Value to print Even Numbers =  ";
cin >> number;

cout << "\nList of Even Numbers from 1 to " << number << " are\n";
while(i <= number)
{
cout << i <<" ";
i = i + 2;
}

return 0;
}```
``````Please Enter Maximum limit Value to print Even Numbers =  35

List of Even Numbers from 1 to 35 are
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 ``````

This C++ print even numbers example allows us to enter a minimum and maximum value. Next, it prints even numbers from minimum to maximum.

```#include<iostream>
using namespace std;

int main()
{
int minimum, maximum;

cout << "\nPlease Enter Minimum limit Value to print Even Numbers =  ";
cin >> minimum;

cout << "\nPlease Enter Maximum limit Value to print Even Numbers =  ";
cin >> maximum;

cout << "\nList of Even Numbers from " << minimum << " to " << maximum << " are\n";
for(int i = minimum; i <= maximum; i++)
{
if ( i % 2 == 0 )
{
cout << i <<" ";
}
}

return 0;
}```
``````Please Enter Minimum limit Value to print Even Numbers =  20

Please Enter Maximum limit Value to print Even Numbers =  70

List of Even Numbers from 20 to 70 are
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 ``````

The first if statement in this C++ print even numbers check whether the minimum value percentage 2 is not equal to 0. If True, it is an odd number, so increment the minimum value by 1; otherwise, enter into the for loop.

```#include<iostream>
using namespace std;

int main()
{
int minimum, maximum;

cout << "\nPlease Enter Minimum limit Value to print Even Numbers =  ";
cin >> minimum;

cout << "\nPlease Enter Maximum limit Value to print Even Numbers =  ";
cin >> maximum;

if (minimum % 2 != 0 )
{
minimum++;
}

cout << "\nList of Even Numbers from " << minimum << " to " << maximum << " are\n";
for(int i = minimum; i <= maximum; i = i + 2)
{
cout << i <<" ";
}

return 0;
}```