C++ Program to check number is even or odd using class


In this program, You will learn how to check number is even or odd using class and object in C++.


if( number % 2 == 0){ }


Example: How to check number is even or odd using class in C++

Run it Now
#include<iostream>
using namespace std;

class Test {
    int num;
public:

    void input() {
        cout << "Enter a Number :";
        cin>>num;
    }

    void check() {
        if (num % 2 == 0) {
            cout << "\nNumber is Even :" << num;
        } else {
            cout << "\nNumber is Odd :" << num;
        }
    }
};

int main() {

    Test tt;

    tt.input();
    tt.check();

    return 0;
}

Output:

Enter a Number :33
Number is Odd :33