Jump to content

Greatest common divisor: Difference between revisions

→‎Alternate solution: remove alternative that brings nothing new but only errors
(→‎Alternate solution: remove alternative that brings nothing new but only errors)
Line 772:
until (zerop y)
finally (return x)))</lang>
===Alternate solution===
{{incorrect|Common Lisp|This program fails for negative b.}}
I use [https://franz.com/downloads/clp/survey Allegro CL 10.1]
 
<lang lisp>
;; Project : Greatest common divisor
;; Date : 2018/03/10
;; Author : Gal Zsolt [~ CalmoSoft ~]
;; Email : <calmosoft@gmail.com>
 
(defun gcds(gcd b)
(loop while (> b 0)
do (setf c gcd)
(setf gcd b)
(setf b (mod c b)))
(write gcd))
(format t "~a" "Greatest common divisor 24 and 32: ")
(gcds 24 32)
</lang>
Output:
<pre>
Greatest common divisor 24 and 32: 8
</pre>
 
=={{header|Component Pascal}}==
BlackBox Component Builder
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.