Detect if number is odd or even. - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Detect if number is odd or even. (
/showthread.php?tid=70747)
Detect if number is odd or even. -
Redirect Left - 27.03.2009
Hello!
How can I tell if a number is odd, or even?
Re: Detect if number is odd or even. -
Rks25 - 27.03.2009
put them in a array? or make calculation system.
Re: Detect if number is odd or even. -
kaisersouse - 27.03.2009
from pawn-lang
Quote:
e1 % e2
Results in the remainder of the division of e1 by e2. The sign
of the remainder follows the sign of e2. Integer division and
remainder have the Euclidean property: D = q*d + r, where
q = D/d and r = D%d.
|
You would have to divide the number by 2 and if there is no remainder...its even. If there is a remainder...its odd.
I >>sUCK<< at math tho..so doulbe check that.
Code:
IsNumberEven(number) {
new remainder = number % 2;
if(remainder > 0) return false;
else return true;
}
^try that, maybe?
Re: Detect if number is odd or even. -
Nubotron - 27.03.2009
Test:
then, !IsOdd = IsEven