How to check enen or odd number in C++

When user will enter value, statement n%2==0 will check wether it is divided by 2 or not if it is divided by 2 output will be “Even number” otherwise it is “odd number”.

The modulus operator is useful in a variety of circumstances. It is commonly used to take a randomly generated number and reduce that number to a random number on a smaller range, and it can also quickly tell you if one number is a factor of another.

If you wanted to know if a number was odd or even, you could use modulus to quickly tell you by asking for the remainder of the number when divided by 2.

#include “stdio.h”
#include “conio.h”
void main()
int num;
cin >> num;
// num % 2 computes the remainder when num is divided by 2
if ( num % 2 == 0 )
cout << num << ” is even “;

Leave a Reply