Table of Contents
Previous Sample | List of Samples | Next Sample

Factor.csh


#  Calculate the prime factors of an integer.
#  Copyright (c) 1989 by Hamilton Laboratories.  All rights reserved.
      
proc factor(n)
   if (n > 3) then
      for i = 2 to floor(sqrt(n)) do
         if (n % i == 0) then
            echo $i
            return factor(n//i)
         end
      end
   end
   return n
end

factor $argv



Previous Sample | List of Samples | Next Sample
Table of Contents



Copyright © 1988-2003 by Hamilton Laboratories. All rights reserved.