- <?php
- function pgcd($diviseur,$reste)
- {
- //
- // Verifie si le reste est egal a 0 si oui on a trouvé le PGCD
- //
- if ($reste == 0)
- {
- echo "<b>PGCD :</b>$diviseur";
- }
- //
- // Sinon on continu de le chercher
- //
- else
- {
- echo "$diviseur/$reste = ".intval(abs($diviseur/$reste))." reste ".$diviseur%$reste."<br />";
- pgcd($reste,$diviseur%$reste); // recursivité
- }
- }
-
- echo 'PGCD('.$_GET['nbr1'].';'.$_GET['nbr2'].')<br /><br />';
- echo max($_GET['nbr1'],$_GET['nbr2']).'/'.min($_GET['nbr1'],$_GET['nbr2']).' = '.intval(abs(max($_GET['nbr1'],$_GET['nbr2'])/min($_GET['nbr1'],$_GET['nbr2']))).' reste '.max($_GET['nbr1'],$_GET['nbr2'])%min($_GET['nbr1'],$_GET['nbr2']).'<br />';
- pgcd(min($_GET['nbr1'],$_GET['nbr2']),max($_GET['nbr1'],$_GET['nbr2'])%min($_GET['nbr1'],$_GET['nbr2']));
- ?>
<?php
function pgcd($diviseur,$reste)
{
//
// Verifie si le reste est egal a 0 si oui on a trouvé le PGCD
//
if ($reste == 0)
{
echo "<b>PGCD :</b>$diviseur";
}
//
// Sinon on continu de le chercher
//
else
{
echo "$diviseur/$reste = ".intval(abs($diviseur/$reste))." reste ".$diviseur%$reste."<br />";
pgcd($reste,$diviseur%$reste); // recursivité
}
}
echo 'PGCD('.$_GET['nbr1'].';'.$_GET['nbr2'].')<br /><br />';
echo max($_GET['nbr1'],$_GET['nbr2']).'/'.min($_GET['nbr1'],$_GET['nbr2']).' = '.intval(abs(max($_GET['nbr1'],$_GET['nbr2'])/min($_GET['nbr1'],$_GET['nbr2']))).' reste '.max($_GET['nbr1'],$_GET['nbr2'])%min($_GET['nbr1'],$_GET['nbr2']).'<br />';
pgcd(min($_GET['nbr1'],$_GET['nbr2']),max($_GET['nbr1'],$_GET['nbr2'])%min($_GET['nbr1'],$_GET['nbr2']));
?>