function GCD3($A, $B, $C) { $great1 = GCD2($A, $B); //var_dump($great1); $var = $great1['divisor']; $great2 = GCD2($C, $var); return $great2; }
function LCM2($A, $B) { $result = GCD2($A, $B); if ($result['status'] == 'have divisor') { $response = $A * ($B / $result['divisor']); } else { $response = 'don\'t have any common multiple'; } return $response; }
function Frac1($a, $b, &$p = 1, &$q = 1) { $gcd = GCD2($a, $b); if ($gcd['divisor'] != 'null') { $p = $a / $gcd['divisor']; $q = $b / $gcd['divisor']; } else { $p = $a; $q = $b; } }
return $result = array('divisor' => $min, 'status' => 'have divisors'); } else { for ($i = 2; $i < $min; $i++) { if ($min % $i == 0 && $max % $i == 0) { $temp = $i; $result = array('divisor' => $i, 'status' => 'have divisor'); /*while($temp <= $min){ $temp = $temp*$temp ; if($min % $temp == 0 && $max % $temp == 0){ $result = array('divisor' => $temp , 'status' => 'have divisors'); } }*/ } else { if ($result['status'] != 'have divisor') { $result = array('divisor' => 'null', 'status' => 'don\'t have divisors'); } } } } return $result; } print_r(GCD2(18, 12)); echo '<br/>'; print_r(GCD2(10, 12)); echo '<br/>'; print_r(GCD2(8, 12)); echo '<br/>'; print_r(GCD2(4, 12)); echo '<br/>'; print_r(GCD2(5, 12)); echo '<br/>';