note 47856 deleted from language.operators.arithmetic by hholzgra
| From: | hholzgra@php.net | Date: | Thu, 02 Aug 2012 15:02:19 +0000 |
| Subject: | note 47856 deleted from language.operators.arithmetic by hholzgra | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-189794@lists.php.net to get a copy of this message | ||
Note Submitter: adam.pippin at accesscomm dot ca
----
To factor a number:
<?php
function factornumber($number)
{
for ($i=1; $i<=($number/2); $i++)
{
if ($number % $i == 0)
{
echo "$i * ".($number/$i)." = $number\n";
}
}
}
factornumber(50);
?>
That script outputs:
1 * 50 = 50
2 * 25 = 50
5 * 10 = 50
10 * 5 = 50
25 * 2 = 50
As you may notice, it makes no attempts at removing duplicates (eg: 5*10 and 10*5), although it
would be trivial to make it do so.