• recursive_recursion [they/them]
    link
    fedilink
    English
    8
    edit-2
    1 year ago

    modulo

    pseudocode:

    if number % 2 == 0
      return "number is even" (is_num_even = 1 or true)
    else
      return "number is odd" (is_num_even = 0 or false)
    

    plus you’d want an input validation beforehand

    • Mac
      link
      fedilink
      16
      edit-2
      1 year ago

      who needs modulo when you can get less characters out of

      while (number > 1) {
        number -= 2;
      }
      return number;
      

      very efficient

      edit: or theres the trusty iseven api

    • @[email protected]
      link
      fedilink
      41 year ago
      #You are an input. You have value! You matter!
      if number % 2 == 0
        return "number is even" (is_num_even = 1 or true)
      else
        return "number is odd" (is_num_even = 0 or false)
      

      Am I doing it right? /S.

    • @[email protected]
      link
      fedilink
      21 year ago

      This code is terrible. If you input 10.66 it returns "number is odd

      It should be:

      if number % 2 == 0
        return "number is even" (is_num_even = 1 or true)
      else
        return "number is not even" (is_num_even = 0 or false)