home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_10_03 / 1003070a < prev    next >
Text File  |  1992-01-13  |  264b  |  25 lines

  1.  
  2. Listing 3
  3.  
  4. //
  5. // gcd.cpp
  6. //
  7. #include <stdlib.h>
  8. #include "mylib.h"
  9.  
  10. long gcd(long x, long y)
  11.     {
  12.     ldiv_t r;
  13.     x = labs(x);
  14.     if ((y = labs(y)) == 0)
  15.         return x;
  16.     do
  17.         {
  18.         r = ldiv(x, y);
  19.         x = y;
  20.         }
  21.     while ((y = r.rem) != 0);
  22.     return x;
  23.     }
  24.  
  25.