A haiku for modulus

This entry was posted by tbielawa on Friday, 4 September, 2009 at

I needed to know
Is this Even or odd, hmm?
I used modulus

This is the simplest way to quickly find out if an integer is even or odd. I’m posting this because I don’t recall my programming lab TAs or professors ever mentioning this simple way to figure that out.

May it save you many lines of code and time!

Update: Suppose I should show an exampe

if ( (your-number % 2) == 0) { echo “that’s an even number” }


Leave a Reply