Back
As an example in pseudocode:
if ((a mod 2) == 0){ isEven = true;}else{ isEven = false;}
if ((a mod 2) == 0)
{
isEven = true;
}
else
isEven = false;
For non-negative integers, you can try the remainder operator %. For your exact instance:
if ((a % 2) == 0){ isEven = true;}else{ isEven = false;}
if ((a % 2) == 0)
This can be modifed to a one-liner:
isEven = (a % 2) == 0;
31k questions
32.8k answers
501 comments
693 users