PW> Hi, all. I found a Euclidean algorithm for finding the HCF of two numbers
PW> and decided to code it :
PW> Do any of you have similar sorts of routines (including that one for the
PW> Sieve of Eratosthenes(sp?) that was discussed recently) ??? Source please
PW> :)
From OZPD...
/*********************************************************************/
/* */
/* This Program Written by Paul Edwards. */
/* Released to the Public Domain */
/* */
/*********************************************************************/
/*********************************************************************/
/* */
/* This function calculates the greatest common divisor of */
/* two integers, using Euclid's algorithm */
/* */
/*********************************************************************/
long gcd(long a, long b)
{
long temp;
long rem;
if (a < b)
{
temp = a;
a = b;
b = temp;
}
rem = a % b;
while (rem != 0)
{
a = b;
b = rem;
rem = a % b;
}
return (b);
}
@EOT:
---
* Origin: X (3:711/934.9)
|