home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / programming / misc_programming / gcd.awk < prev    next >
Text File  |  1990-02-08  |  352b  |  13 lines

  1. # calculate the Greatest common divisor of each pair of inputs
  2.  
  3. {
  4.         arg1 =$1; arg2 = $2;
  5.         while (arg1 != arg2) {
  6.                 if (arg1 > arg2)
  7.                         arg1 -= arg2
  8.                 else
  9.                         arg2 -= arg1
  10.         }
  11.         print "The greatest common divisor of", $1, "and", $2, "is", arg1
  12. }
  13.