Thread: How do u use........

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    6

    Question How do u use........

    How do you use % to determine if a number is even. I don't understand.

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,862
    >How do you use % to determine if a number is even. I don't understand.
    Code:
    if ( val % 2 == 0 )
      // Even
    Divide the value by two, if the remainder is 0 then the value was evenly divided by two and is thus an even number. The % operator saves you from performing several operations in that it simply returns the remainder.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed