This is an old revision of the document!
Anders Genomgång 06 - Fakultet och talföljd
<?php include('head.php'); // Beräkna fakultet. $tal = 4; echo 'Fakulteten av ' . $tal . ':<br>'; echo $tal . '! = '; $resultat=1; $i=$tal; while ($i >= 1){ // Börja på tal och "vandra" ner till 1 $resultat *= $i; // Multiplicera resultatet med $i varje varv. echo $i; if ($i > 1){ // Om det inte är sista varvet echo ' * '; } $i--; } echo ' = ' . $resultat; include('foot.php'); ?>