1

If the input is a number, how can I write a procedure that checks every digit and produces an output equal to the number of odd digits in this number?

I'm thinking about turning the number into a list first, but I'm trying to think of an easier solution.

Also, we're not allowed to use "odd?". So instead of using "odd?" to check whether or not a digit is odd, we can use "quotient"

gurdingering
  • 207
  • 5
  • 12
  • 3
    Is this an assignment? What have you tried? You could cast the number to string, iterate over its characters and use the modulus operator to find out odd or even for each. – marekful May 29 '15 at 16:51

1 Answers1

1

Rather than convert to a string like in marekful's comment, try recursively taking off the most significant digit at a time using the mod operation. Then, you can use the quotient function to test for odd or even.

adao7000
  • 3,632
  • 2
  • 28
  • 37