C++ Program to find odd or even number without using modulus operator
Program for finding odd or even number is one of the basic programs that every programmer must know. Currently, we all have been doing it with the help of % operator (modulus or remainder operator). But, most of the people might not know there is another quick way to find whether a given number is odd or even.
Program to find EVEN or ODD without using Modulus (%) Operator in C++
Output
In this program, we are simply reducing the given number by 2 until it is either 0 or 1. If it is even, the end result will be 0 and if it is odd, the loop will not go to negative number, therefore the result for odd will be 1.
Then we are simply checking if number (n) is 0, it is even and if it is 1, the number is odd.
need an explanation for this answer? contact us directly to get an explanation for this answer