note 36201 added to ref.math
| From: | fabien_mornand at yahoo dot fr | Date: | Tue, 30 Sep 2003 19:46:13 +0000 |
| Subject: | note 36201 added to ref.math | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-57508@lists.php.net to get a copy of this message | ||
here is an algorithm to calculate gcd of a number. This is Euclid algorithm i was studying in Maths.
I've converted it in php for the fun.
<?php
if($a && $b)
{ $ax=$a; $bx=$b;
$r=fmod($a,$b);
if(!$r){$rx=$r;}
while($r){
$rx=$r;
$a=$b;
$b=$r;
$r=fmod($a,$b);
}
}
echo 'PGCD ('.$ax.' , '.$bx.' ) = '.$rx;
?>
----
Manual Page -- http://www.php.net/manual/en/ref.math.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+36201
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+36201&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+36201&report=yes