in c++ how do you check if a number is odd or even?
thanks
Printable View
in c++ how do you check if a number is odd or even?
thanks
num % 2
There is a FAQ entry with just that title. You may find that, and other useful stuff here:
http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
--
Mats
thanks !!
how do i check if a number is not divisible by 2?
not divisible by 2 == odd.
Or you could read what % does.
Or ... and so on.
The modulus operator (%) returns the remainder of a division. So say you divide 3 by 2. The remainder is 1. If the remainder is 0, the number must be even; otherwise, if it is odd, the remainder is not 0.