Il fattoriale != di un numero in Php con i tre cicli di iterazione

<html>
<head>
<title>fattoriale</title>
</head>
<body>
    <table border="1" bgcolor="lightblue" width="100%" height=10%>
            <tr>
              <td width="15%" align="center"><a href="../../index.html"><img src="image.png" width=220 height=150></a></td>
              <td width=70% align="center"><font face=arial size=6>Fattoriale</font></td>
              <td width="15%" align="center"><a href=../../index.html> HOME/indietro</a></td>
            </tr>
     </table>
         DIGITARE UN NUMERO INTERO E POSITIVO
             <form action="fattoriale2.php" method="POST">
                numero:<input name="numero" size="7" maxlength="7">
                <input type="submit" value="invia" name="inviat">
                <input type="reset" value="cancella">
            </form>
                <?php
                // verifica che l'utente abbia digitato il tasto invia
                    if(isset($_POST['inviat'])) {
                        $numero=$_POST['numero'];
                        if ($numero>=0 && $numero==floor($numero)) {
                            $fattor=1;
                            if ($numero==0)  echo "$numero!=1";
                            else {
                                $prodot=1;
                                do {
                                    $prodot=$prodot*$fattor;$fattor++;
                                } while ($fattor<=$numero);
                               echo "do $numero!=$prodot<p>";
                               //while
                               $prodot=1;
                               $fattor=1;
                                   while ($fattor<=$numero) {
                                    $prodot=$prodot*$fattor;$fattor++;
                                   }
                                echo " while $numero!=$prodot<p>";
                                //for
                                $prodot=1;
                                   for ($fattor=1;$fattor<=$numero;$fattor++) {
                                    $prodot=$prodot*$fattor;
                                   }
                                echo " for $numero!=$prodot<p>";
                               
                            }
                           
                        }
                        else echo "errore,mi dispiace";
                    }
                ?>
</body>
</html>

Commenti

Post popolari in questo blog

Simulazioni di reti (con Cisco Packet Tracer)

Esercizi sulla rappresentazione della virgola mobile IEEE 754 (Floating Point)