C++ Program to Print Even Numbers

C++ Program to Print Even Numbers

How to print Even Numbers in a given range? We can do it by using a Loop and a Conditional Statement. Here we used "while loop" and "if statement" to get our desired output.

Printing Odd Numbers by C++ :



#include <iostream>
using namespace std;

int main() 
{
    int n, i=1;
    
    cout << "Enter the Maximum Value : ";
    cin >> n;
    cout << "Even Numbers in the given range : \n";

    while (i <= n)
    {
        if(i % 2 == 0)
            cout << i << " ";
        i++;
    }

    return 0;
}


Output :