Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Factorial in Scheme (See related posts)

;Calculate the factorial of a number
;(factorial 5) = 1 * 2 * 3 * 4 * 5 = 120
;(factorial 50) = 30414093201713378043612608166064768844377641568960512000000000000
(define factorial
  (lambda (n)
    (if (= n 0) 1
        (* n (factorial (- n 1))))))

You need to create an account or log in to post comments to this site.


Click here to browse all 4858 code snippets

Related Posts