Page 1 of 1 1
Topic Options
#161746 - 2006-05-08 03:34 PM This should be easy: Determining even & odd numbers?
MrOctober Offline
Lurker

Registered: 2006-04-28
Posts: 4
Anyone have some sample code or a function to determine whether a number is even or odd? Actually, in this case the "number" would be in a string but that isn't a big deal. I can easily do this in PERL using the mod function but I can't find a similar function in Kixtart. I'm sure this is easier then I am making it.
Top
#161747 - 2006-05-08 04:17 PM Re: This should be easy: Determining even & odd numbers?
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
It is easy:
Code:

$iNum=3
"The number "+$iNum+" is "+IIF($iNum MOD 2,"odd","even")+@CRLF


Top
#161748 - 2006-05-08 04:20 PM Re: This should be easy: Determining even & odd numbers?
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
sample:

Code:

Break On

$string = "23"
$result = "even","odd"

"Number is " + $result[val($string) mod 2] ?

get $


exit 1


play a bit with the $string value and you will see
_________________________



Top
#161749 - 2006-05-08 06:37 PM Re: This should be easy: Determining even & odd numbers?
MrOctober Offline
Lurker

Registered: 2006-04-28
Posts: 4
Thanks! That does the trick!
Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.061 seconds in which 0.034 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org