The Grinnell Scheme Web: The gcd procedure

What does the gcd procedure do?

It computes and returns the largest integer that evenly divides all of its operands. (But if it is not given any operands, or if all of its operands are zero, the gcd procedure returns 0.)

> (gcd 165 70)
5
> (gcd -165 -70)
5
> (gcd 1000 1001)
1
> (gcd 12 18 30)
6
> (gcd 360)
360
> (gcd 0 12)
12
> (gcd 60 84 140 210)
2
> (gcd 0 0 0)
0
> (gcd)
0
Do all the operands have to be integers?

That's right. If you think about it, that's implied by the definition: Non-integers are never evenly divisible by integers.


Next topic
Previous topic
Table of contents


This document is available on the World Wide Web as

http://www.math.grin.edu/~stone/scheme-web/gcd.html


created June 24, 1995
last revised December 29, 1995

Copyright 1995 by John David Stone (stone@math.grin.edu)