Calculando determinante 2x2 php

En este ejemplo muestro un código en php con el que podrán calcular el determinante 2x2 para lo cual solo deberían de entender la lógica en como se resuelven así:
Determinante
Si A= a    b
        c    d

 El determinante de A/delim{|}A{|}) seria:
aqui el codigo
 

<html> 
  <head> 
  <title>Calculando determinantes 2x2 php</title> 
  </head> 
  <body>
 
  <?php
  //editando funcion para calcular ls determinantes
  function Calcular_determinante($a,$b,$c,$d){
  /*
 siendo
 |a00 a01|   |$a $b|
 |a10 a11| = |$c $d|
 determinante = $a*$d-$b*$c
 */
 $total=$a*$d-$b*$c;
//si el total es 0 no tiene determinante
if($total!=0){
echo "Total: ".$total;
}
else
{
echo "Error el det. da 0 ";  
    }
  }?>
<form action="determinante 2x2 php.php" method="post">
<br>Ingrese los valores<br>
<input type="text"  name ="a00">         <input type="text"  name ="a01">
<br><input type="text"  name ="a10">     <input type="text"  name ="a11">    
<br><input type="submit" name="calcular" value="calcular" /><br>
 <?php 
 //en caso se presione el boton de calcular mandara 
 // los valores que tengas los text a00,a01,a10,a11 a la funcion
 //Calcular_determinante:
 if ($_POST['calcular']) {Calcular_determinante($_REQUEST[a00],$_REQUEST[a01],$_REQUEST[a10],$_REQUEST[a11]);} 
 ?>
 </form>


  
  </body> 
</html> 






Descargar ejemplo:


Comentarios

Populares

Buscar en este blog