lastDigit.hs
{- Return the last digit of a number -} getLastDigit :: Integer -> Integer getLastDigit num | (num < 0) = ((-1) * num) `rem` 10 | otherwise = num `rem` 10
*Main> :load lastDigit.hs [1 of 1] Compiling Main ( lastDigit.hs, interpreted ) Ok, modules loaded: Main. *Main> *Main> getLastDigit (-1234) 4 *Main> *Main> getLastDigit 1234 4
No comments:
Post a Comment