Your Ad Here

Posted By

rwczippy on 06/18/08


Tagged

php lcm gcm


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

rwczippy


LCM/GCM PHP


 / Published in: PHP
 

URL: http://www.ideashower.com/our_solutions/leastgreatest-common-mulitple-lcmgcm-in-php-and-javascript/

  1. function gcm($a, $b) { return ( $b == 0 )?($a):( gcm($b, $a % $b) ); }function lcm($a, $b) { return ( $a / gcm($a,$b) ) * $b; }function lcm_nums($ar) {
  2. if (count($ar) > 1) {
  3. $ar[] = lcm( array_shift($ar) , array_shift($ar) );
  4. return lcm_nums( $ar );
  5. } else {
  6. return $ar[0];
  7. }
  8. }

Report this snippet  

You need to login to post a comment.