[EMAIL PROTECTED] said:
>
>
>Does anyone know a simple way to determine if a number is odd or even?  For 
>example 220 would come out even while 221 would come out as an odd number.

perl -e '($number % 2)?print "even":print "odd"; print "\n";'

% is the modulus operator, and returns the remainder from a division of
its left operand by its right.

221 % 2 = 1 which is true if tested inside an if statement or whatever.
220 % 2 = 0 which is false in an if statement.

Hope that helps.
-- 
Kind regards,
Hal Ashburner

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to