TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Paul Wankadia
from: Paul Edwards
date: 1996-09-29 15:06:46
subject: Maths routines

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)

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.