How do I find out if a number is even or odd?
for example:
$var = 7
if ( $var is an odd number ){ perform this function } elseif ($var is an even number) { perform this function }
thanks, Chris
Use the mod operator:
if ($var % 2 == 1 ) { should be odd } else { even }
thanks
This worked, but does the "mod operator" do exactly?
thanks Chris
dear sir, i m aman and i do java script but i have content some problems so plz help me, i want script of even and odd number and also prime number with the help of Array. thanks,
the mod operator returns the remainder in a division operation
for instance: 9 / 2 = 4.5 OR: 9 / 2 = 4 with a remainder of 1.
if you use the %, it will return whatever the remainder is.