Robson » Code » PHP » Proper Divisors

 
<?
   // proper divisors finder v1.0
   
   // returns array of the proper divisors of a number
   function proper_divisors($number)
   {
       for ($n = 1; $n < ceil($number/2)+1; $n++)
           if (!($number % $n))
               $divisors[] = $n;
       return $divisors;
   }
 
   // * example use - display proper divisors of numbers 1 to 25 */
   for ($n = 1; $n <= 25; $n++)
       echo $n . ' = ' . implode(', ', proper_divisors($n)) . '<br />';
?>
 
© 2004-17 robson | cc unless stated