a -> a! (factorial with argument)

module Main where
import IO

fact :: Integer -> Integer
fact 0 = 1
fact n = n * fact (n – 1)

readNum :: IO Integer
readNum = readLn

main = do
hSetBuffering stdout NoBuffering
putStr “Enter a: ”
a <- readNum
putStr (“a! = ” ++ show (fact(a)) ++ “\n”)

Leave a comment

Your comment