Source language: Translate to:

Odd or even?

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Odd or even?

Postby magarcan » Fri Aug 26, 2011 10:51 am

How can I know if a number si odd or even? Thanks!!
magarcan
 
Posts: 12
Joined: Wed Nov 01, 2006 1:28 pm

Postby magarcan » Fri Aug 26, 2011 11:09 am

This is the way:
Apoleo wrote:Hi, thanks for the information :wink:.

I know ln(x) is undefined when x <= 0 :?. I have thought in a code more efficient than before one.

:arrow: Just to know if the number 'y' is even or odd. (-1^y)

Code: Select all
Math "[y]/2" "0" "[z]"
Math "[y]-([z]*2)" "0" "[z]"
If "[z]" "=" "0"
 .Even
 SetVar "[x]" "1"
Else
 .Odd
 SetVar "[x]" "-1"
EndIf


Saludos!
magarcan
 
Posts: 12
Joined: Wed Nov 01, 2006 1:28 pm

OR THIS

Postby virger » Fri Aug 26, 2011 8:16 pm

math "(trunc([n]/2))*2" "0" "[rs]"
if "[rs]" "=" "[n]"
alertbox "" "Even"
endif

PURA VIDA
User avatar
virger
 
Posts: 524
Joined: Mon Sep 18, 2006 12:21 pm
Location: Costa Rica, America Central


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 1 guest