Detect if number is odd or even.
#3

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?
Reply


Messages In This Thread
Detect if number is odd or even. - by Redirect Left - 27.03.2009, 15:01
Re: Detect if number is odd or even. - by Rks25 - 27.03.2009, 15:40
Re: Detect if number is odd or even. - by kaisersouse - 27.03.2009, 16:14
Re: Detect if number is odd or even. - by Nubotron - 27.03.2009, 16:19

Forum Jump:


Users browsing this thread: 1 Guest(s)