C++ Program to display even numbers from 1 to 100


In this Program, You will learn how to display even numbers from 1 to 100 in C++.


if(i % 2 == 0) {
  //statement
}

Example: How to display even numbers from 1 to 100 in C++.

#include<iostream>
using namespace std;

int main() {

    int i;

    for (i = 1; i <= 100; i++) {
        if (i % 2 == 0) {
            cout << "Even number:" << i << endl;
        }
    }

    return 0;
}

Output:

Even number:2
Even number:4
Even number:6
Even number:8
Even number:10
Even number:12
Even number:14
Even number:16
Even number:18
Even number:20
Even number:22
Even number:24
Even number:26
Even number:28
Even number:30
Even number:32
Even number:34
Even number:36
Even number:38
Even number:40
Even number:42
Even number:44
Even number:46
Even number:48
Even number:50
Even number:52
Even number:54 
Even number:56
Even number:58
Even number:60
Even number:62
Even number:64
Even number:66
Even number:68
Even number:70
Even number:72
Even number:74
Even number:76
Even number:78
Even number:80
Even number:82
Even number:84
Even number:86
Even number:88
Even number:90
Even number:92
Even number:94
Even number:96
Even number:98
Even number:100