|
Odd or Even
This will check whether a number is odd or even
, this is a common function found on other programming sites
for different languages , lets look at our function.
<%
function OddOrEven(ByVal intNumber)
If (intNumber MOD 2 = 0 ) Then
Response.Write ("Your number is even<br>")
Else
Response.Write ("Your number is odd<br>")
End If
end function
%>
This is a fairly simple example to understand
, we get the user entered number (intNumber) and then we use
the modulus operator (MOD) to work out the remainder after division
. Of course if you divide an even number by 2 there will be
no remainder and alternately an odd number there will be a remainder.
Now we will test this function
<%
OddOrEven(2)
OddOrEven(97)
%>
This works out whether 2 and 97 are odd or even
|