[scilab-Users] Odd and Even numbers

Ralph Ewig ralph at open-aerospace.org
Tue Oct 27 15:38:39 CET 2009


If you don't like (or have) modulo for some reason, this also works:

function [out]=iseven(x)
   if round(x/2)==x/2
      out = true
   else
      out = false
   end
   return


works in just about any programming language (with syntax adapted as
needed).

Ralph


Francis Drossaert wrote:
> You can use the modulo command. This is how matlab does, I believe. 
> 
> For example:
> 
> if modulo(x,2) == 0
> 	disp('x is even');
> else
> 	dsip('x is odd');
> end
> 
ts and response string, may contain proprietary information which is
confidential and may be legally privileged. It is for the intended
recipient only. If you are not the intended recipient or transmission
error has misdirected this e-mail, please notify the author by return
e-mail and delete this message and any attachment immediately. If you
are not the intended recipient you must not use, disclose, distribute,
forward, copy, print or rely on this e-mail in any way except as
permitted by the author.

-- 
Dream of Space? Make it Real.
http://www.OpenAerospace.Org/



More information about the users mailing list