How would you make code to find out if a number is even or odd?

@CodeHelp

# How do you find whether a number is even or odd?

**CoderOfMagic**#5

Yeah I know I didnât

;-;

Sorry Iâm in a bad mood

So, want me to explain more?

**Petrichor**#8

While I was typing this, @MISSION_IMPOSSIBLE gave another cool answer. I think that this one is easier, though. It also makes the file smaller, though that isnât important for stuff youâd be coding manually.

All even numbers are multiples of two.

So that means that if it is even, it will be evenly divisible by 2, if it is odd, it will be 1 away from a multiple of 2.

When a number is evenly divisible by another number, it has no remainder after dividing.

So how do we check for that? Modulo is how you can get the remainder after a division.

So we would use modulo to get a remainder after a division by 2.

So we put number % 2 (number modulo 2) in. But this doesnât give âevenâ and âoddâ, it gives a number.

So how do we know which numbers mean even and which mean odd?

Which numbers can it give us?

We know 0, which is when it is evenly divisible by 2. That means that it is even.

It can also give 1, which is not evenly divisible by two and means that the original number wasnât either.

It canât give 2, because two is a multiple of 2.

**So that means that number % 2 (number modulo 2) == 0 when number is even, and 1 when number is odd.**

If a leader sees this, maybe move this conversation to a new topic.

**Cocoa_Viola**#15

This is how:

An even number is always going to be a whole number. They can be divided equally by 2. For example 4 can be divided into 2 and 2, so it is even. 6 can be divided into 3 and 3, so it is even. Even numbers end in 0, 2, 4, 6, and 8.

Odd numbers are always numbers that cannot be divided equally by 2. For example, 3 can only be divided into 2 and 1, so it is odd. 5 can only be divided into 3 and 2, so it is odd. All odd numbers end in 1, 3, 5, 7, and 9.

**Awesome_E**#16

@JACG2018MASTER easiest solution:

Use modulo, modulo (%) is the remainder.

Number % 2 = remainder of the number divided by 2.

If that equals zero, the numbr is even