Define a function dropOdds :: Int -> Int with the following behaviour.
For any positive number m, dropOdds m is got by dropping all the odd digits
in m. (If all the digits in the number are odd, the answer should be 0.)
Test cases:
dropOdds 0 = 0
dropOdds 8 = 8
dropOdds 1357 = 0
Top comments (2)
dropOdds :: Int -> Int
dropOdds x
| x > 10 = 10 * dropOdds restDigits + dropOdds firstDigit
| otherwise = dropOddsOneDigit x
where
firstDigit = x
mod
10restDigits = x
div
10dropOddsOneDigit x
| x
mod
2 == 0 = x| otherwise = 0
Are you ennrolled in the NPTEL course?