Ver Mensaje Individual
  #9 (permalink)  
Antiguo 21/12/2009, 13:22
Osdiwe
 
Fecha de Ingreso: diciembre-2009
Mensajes: 438
Antigüedad: 14 años, 4 meses
Puntos: 16
Respuesta: Simplificar Fracciones desde PHP

Te paso las funciones traducidas a php. Espero no haverme dejado nada para convertir.

Código PHP:
function go($input1$input2) {

    
$hcfval hcf($input1,$input2);
  
    
$answer $hcfval;
    
$ans1 = ($input1/$hcfval);
    
$ans2 = ($input2/$hcfval);
    
    
$ex "The Greatest Common Factor is " hcfval "<br /><br />";
    
    if (
$hcfval == 1) {
        
ex .= "(No reduction possible)";
    } else {
    
        
ex .= "The fraction simplifies like this: ";
        
        
ex .= "<span class=\"frac-large\"><sup>" $input1 "</sup>/<sub>" $input2 "</sub></span>";
        
ex .= " &raquo;&raquo; ";
        
ex .= "<span class=\"frac-large\"><sup>" . ($input1/$hcfval) . "</sup>/<sub>" + ($input2/$hcfval) + "</sub></span>";
    
    }
    echo 
$ex;
  
}

function 
hcf($text1,$text2){
  
$gcd=1;
  if (
$text1>$text2) {$text1=$text1+$text2$text2=$text1-$text2$text1=$text1-$text2;}
  if ((
$text2==(round($text2/$text1))*$text1)) {$gcd=$text1}else {
   for (
$i round(text1/2) ; $i 1$i=$i-1) {
    if ((
$text1==(round($text1/$i))*$i))
     if ((
$text2==(round($text2/$i))*$i)) {$gcd=$i$i=-1;}
   }
  }
  return 
$gcd;
}

function 
lcm($t1,$t2){
  
$cm=1;
  
$f=hcf($t1,$t2);
  
$cm=$t1*$t2/$f;
  return 
$cm;


Debes llamar a la función "go" pasándole como parámetros las dos partes de la fracción. Ejemplo:

Fracción -> 2/4
Llamada a la función -> go(2, 4);

Espero que te sirva y que funcione correctamente. Ya informarás.