[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3879
  • Last Modified:

GCD of two numbers in LISP

How to write a program in LISP to find the GCD of two numbers.
0
rmvprasad
Asked:
rmvprasad
1 Solution
 
ozoCommented:
(defun gcd (a b)
    (label ((_gcd (lambda (a b)
        (cond ((zerop b) a)
            ((lessp a b) (_gcd a (remainder b a)))
            (t (_gcd b (remainder a b)))))))
    (_gcd (natural (abs a)) (natural (abs b)))))
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now