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

#1

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

11 Likes
#2

Set variable to random

Check once if variable equals prime number

1 Like
#3

Umm that did not help

2 Likes
#4

Check once if [(Number)Ăˇ2]=[(round((Number)Ăˇ2)]
If so, itâs even.

4 Likes
#5

Yeah I know I didnât
;-;
Sorry Iâm in a bad mood
So, want me to explain more?

2 Likes
#6

THANK YOU SO MUCH!

3 Likes
#7

Youâre welcome!

1 Like
#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.

15 Likes
#9

What are you using it for?

1 Like
#10
4 Likes
#11

That looks amazing! BTW, I made it 4-5 times faster.

5 Likes
#12

If (number%2 = 0) it is even
% is modulo

1 Like
#13
4 Likes
#14

Done.

4 Likes
#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.

1 Like
#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

2 Likes
#17

Iâve always done it like this:

1 Like
#18

Me too, till I found modulo

closed #19
archived #20