I was wondering if there was a way to figure out if a number is even or odd. I really need this for my project so please reply.
Offline
thelasthorizon wrote:
I was wondering if there was a way to figure out if a number is even or odd. I really need this for my project so please reply.
Yep! I'm not sure if this is the simplest way, but it works!
<when green flag clicked>
<forever>
<repeat until> << <( <{ number }> <=> 2 )> <or> <( <{ number }> <<> 2 )>>>
<set{ number }to((( <{number }> <-> 2 ))
<if> <( <{ number }> <=> 2 )>
<say[ It is even!
<else>
<say[ It is odd!
I hope this helps!
Offline
Using the mod block is the simplest way.
[blocks](( number <mod> 2 ))[/blocks]
(number) MOD (2) will give an answer of zero if the number is even, or 1 if the number is odd.
Last edited by Mayhem (2008-12-14 03:58:56)
Offline