Hamilton LaboratoriesHamilton C shell 2012User guideSamples

factor.csh

Oregon Coast

factor.csh
Previous | Next

#  Calculate the prime factors of an integer.
#  Copyright (c) 1989-2012 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 | Next