home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
OL.LZH
/
PROCS.LZH
/
GCD.ICN
< prev
next >
Wrap
Text File
|
1991-07-13
|
732b
|
33 lines
############################################################################
#
# Name: gcd.icn
#
# Title: Compute greatest cmmon denominator
#
# Author: Ralph E. Griswold
#
# Date: May 11, 1989
#
############################################################################
#
# This procedure computes the greatest common denominator of two
# integers. If both are zero, it fails.
#
############################################################################
procedure gcd(i,j)
local r
if i = j = 0 then fail
if i = 0 then return j
if j = 0 then return i
i := abs(i)
j := abs(j)
repeat {
r := i % j
if r = 0 then return j
i := j
j := r
}
end