Skip to content

Instantly share code, notes, and snippets.

@Wollw
Created April 16, 2012 16:49
Show Gist options
  • Select an option

  • Save Wollw/2399916 to your computer and use it in GitHub Desktop.

Select an option

Save Wollw/2399916 to your computer and use it in GitHub Desktop.
main = do
putStrLn "Enter a number:"
n <- getLine
putStrLn $ "The factorial of " ++ n ++ " is:"
print $ factorial $ read n
factorial :: (Num a) => a -> a
factorial 0 = 1
factorial n = n * factorial (n - 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment