in c++ how do you check if a number is odd or even?
thanks
This is a discussion on even and odd numbers within the C++ Programming forums, part of the General Programming Boards category; in c++ how do you check if a number is odd or even? thanks...
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
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
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.
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^