Results 1 to 10 of 10

Thread: finding if a number is even?

  1. #1
    Join Date
    Aug 2007
    Posts
    282
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default finding if a number is even?

    SCAR Code:
    if L = 0 or
         L = 2 or
         L = 4 or
         L = 6 or
         L = 8 or
         L = 10 or
         L = 12 or
         L = 14 or
         L = 16 or
         L = 18 or
         L = 20 or
         L = 22 or
         L = 24 or
         L = 26 or
         L = 28 or
         L = 30 or
         L = 32 or
         L = 34 or
         L = 36 or
         L = 38 or
         L = 40 or
         L = 42 or
         L = 44 or
         L = 46 or
         L = 48 or
         L = 50 then

    is there an easier way then that? (just 0-50)

  2. #2
    Join Date
    Jul 2007
    Posts
    137
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    http://www.villavu.com/forum/showthread.php?t=14623

    I'm not sure if it works, but there it is.
    Do not propose an idea of peculation without evidence of such action.

    http://cashcrate.com/704591 click here and make money!

  3. #3
    Join Date
    Jun 2007
    Location
    I'm not sure...
    Posts
    581
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Woot! Thats my thread!

    Use
    SCAR Code:
    function even(i:integer):boolean;
    begin
      result:=(i mod 2 = 0);
    end;
    because its shorter.
    ---------------------------------------------------------


    Pm me if you need any math functions made. Me = l0ving t3h mathz

    ---------------------------------------------------------

  4. #4
    Join Date
    Aug 2007
    Posts
    282
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    sorry, but could you explain how that works? like, what does mod to?

  5. #5
    Join Date
    Jun 2007
    Location
    I'm not sure...
    Posts
    581
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    It divides the 1st number by the second number and returns the remainder.

    EG:
    Code:
    1 mod 2 = 1
    Same as
    1/2=0 with 1 remainder
    --------------------------
    4 mod 2 = 0
    Same as
    4/2=2 with 0 remainder
    soooo.....
    In the earlier code,
    SCAR Code:
    (i mod 2 = 0)
    will return true if the number is divisible by 2 (the number/2 = 0) and the definition of an even number is one that is divisible by 2... So if it returns true, the # is even.
    ---------------------------------------------------------


    Pm me if you need any math functions made. Me = l0ving t3h mathz

    ---------------------------------------------------------

  6. #6
    Join Date
    Aug 2007
    Posts
    282
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    alright thanks TONS


  7. #7
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    2,984
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    SCAR Code:
    function IsEqual(Number: Integer): Boolean;
    var
      Divided: Extended;
    begin
      Divided := Number / 2;
      Result := Divided = (Round(Number / 2));
    end;

    There we go
    Administrator's Warning:


  8. #8
    Join Date
    Sep 2006
    Location
    New Jersey, USA
    Posts
    5,347
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    IsEqual? IsEven?

    His is shorter, too
    Interested in C# and Electrical Engineering? This might interest you.

  9. #9
    Join Date
    May 2007
    Location
    baltimore, md
    Posts
    836
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    woot thats my function
    SCAR Code:
    function even(i:integer):boolean;
    begin
      result:=(i mod 2 = 0);
    end;

  10. #10
    Join Date
    Jun 2007
    Location
    I'm not sure...
    Posts
    581
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Yep. Jhildy only did it 'cause I forgot mod for like 5 min... *Glares @ Jhildy*

    Btw, heres my original one XD
    SCAR Code:
    Const i=10
    Function Even(i:Extended):Boolean;
      Var q,r:Extended;
      Begin
        r:=(i/2);
        q:=Trunc(r);
        If(SameValue(r,q))Then
        Begin
          Result:=True;
          Exit;
        End;
        Result:=False;
      End;
     
    begin
    ClearDebug;
    If(Even(i))Then
      Writeln('It is even');
    If(Not(Even(i)))Then
      Writeln('It''s not even');
    end.
    ---------------------------------------------------------


    Pm me if you need any math functions made. Me = l0ving t3h mathz

    ---------------------------------------------------------

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Checking if a number is a whole number or not?
    By Sandstorm in forum OSR Help
    Replies: 4
    Last Post: 10-26-2008, 04:40 PM
  2. Replies: 3
    Last Post: 09-23-2008, 03:37 AM
  3. Your number?
    By ub3r |<1||3r*1337* in forum News and General
    Replies: 4
    Last Post: 08-13-2006, 09:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •