###
__Even or odd number in C++__

####
__Theory:__

Even or odd in C++ is a simple C++ program to check a given number is Even or odd. A user will enter an number and the program will check whether the given number is Even or odd and outputs the result.

**evenOrOdd**is a class declared and int checknum() is the member function which is used to check whether the given number is Even or odd number.####
__Logic:__

In this program we are using the concepts of class and objects. Even numbers are the integer numbers which can be completely divided by the number 2 example 4, 0, 560 etc. Odd numbers are the integer numbers which can not be completely divided by 2 example 3, 5 27 etc. To check that we are using a simple if statement in our program.

if(n%2==0)

cout<<n<<" is an even number ";

else

cout<<n<<" is an odd number ";

####
__Program:__

C++ program to check given number is even or odd.

#include<iostream>

using namespace std;

class evenOrOdd{

public:

void checknum(int n)

{

if(n%2==0)

{

cout<<n<<" is an even number ";

}

else

{

cout<<n<<" is an odd number ";

}

}

};

int main()

{

evenOrOdd obj1;

int n;

cout<<"Please enter the number"<<endl;

cin>>n;

obj1.checknum(n);

cout<<endl;

return 0;

}

__Output 1:__
Please enter the number

0

0 is an even number

__Output 2:__
Please enter the number

5

5 is an odd number

__Output 3:__
Please enter the number

7

7 is an odd number

## No comments:

## Post a Comment