Haskell Program to print factorial of a number
Program
module Main where
import Text.Printf
factorial :: Integer -> Integer
factorial 0 = 1
factorial n = n * factorial (n - 1)
line x = printf "%d! = %d\n" x $ factorial x
main = mapM_ line [0..8]
Output
$ ghc factorial.hs
[1 of 1] Compiling Main ( factorial.hs, factorial.o )
Linking factorial ...
$ ./factorial
0! = 1
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
7! = 5040
8! = 40320