Last active
December 28, 2019 20:39
-
-
Save gsscoder/d91655c66a7b29de10f11f5ba21cd925 to your computer and use it in GitHub Desktop.
Haskell program to calculate factorial of a number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- $ ./factorial 10 | |
-- 3628800 | |
import System.Environment | |
main = do | |
args <- getArgs | |
let n = args !! 0 | |
putStrLn (show (factorial (read n))) | |
factorial :: (Integral 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