3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $n = (int)$_POST['n']; $r = (int)$_POST['r']; $model = $_POST['model']; function factorial($n) { if($n == 0 or $n == 1) { return 1; } else { return($n * factorial($n-1)); } } // fungsi permutasi perulangan function permutasi_perulangan($n, $r) { return(pow($n, $r)); } // fungsi permutasi tak berulang function permutasi_tak_berulang($n, $r) { return(factorial($n)/factorial($n-$r)); } ?> <html> <head> <title>Fungsi Permutasi dengan PHP</title> </head> <body> <center> <form method="post"> <table cellpadding=5 cellspacing=2 border=1> <tr> <td>Permutasi</td> <td> <select name="model"> <option value="ulang">Permutasi Perulangan</option> <option value="tidak">Permutasi Tak Berulang</option> </select> </td> </tr> <tr> <td>N</td> <td><input type=text name="n" size=5 value=<? echo $n; ?> /></td> </tr> <tr> <td>M</td> <td><input type=text name="r" size=5 value=<? echo $r; ?> /></td> </tr> <tr> <td colspan=2 align=center><input type="submit" value="Permutasi" /></td> </tr> </table> </form> <?php if(isset($n) && isset($r) && isset($model) && $n != 0 && $r != 0) { if($model == "ulang") { echo "<h2>$n<sup>$r</sup> = "; echo permutasi_perulangan($n, $r); echo "</h2>"; } else { echo "<table border=0 cellpadding=0 cellspacing=0>"; echo "<tr><td align=center style=\"border-bottom: solid #000;\"><font size=6>$n!</font></td>"; echo "<td rowspan=2 valign=middle><font size=6>&nbsp; = ". permutasi_tak_berulang($n ,$r) ."</font>"; echo "</tr>"; echo "<tr><td align=center><font size=6>$r !($n - $r)!</font></td></tr></table>"; } } ?> </center> </body> </html>
Output for 5.4.0 - 7.1.0
Notice: Undefined index: n in /in/V0qRW on line 2 Notice: Undefined index: r in /in/V0qRW on line 3 Notice: Undefined index: model in /in/V0qRW on line 4 <html> <head> <title>Fungsi Permutasi dengan PHP</title> </head> <body> <center> <form method="post"> <table cellpadding=5 cellspacing=2 border=1> <tr> <td>Permutasi</td> <td> <select name="model"> <option value="ulang">Permutasi Perulangan</option> <option value="tidak">Permutasi Tak Berulang</option> </select> </td> </tr> <tr> <td>N</td> <td><input type=text name="n" size=5 value=0 /></td> </tr> <tr> <td>M</td> <td><input type=text name="r" size=5 value=0 /></td> </tr> <tr> <td colspan=2 align=center><input type="submit" value="Permutasi" /></td> </tr> </table> </form> </center> </body> </html>
Output for 5.3.0 - 5.3.29
Notice: Undefined index: n in /in/V0qRW on line 2 Notice: Undefined index: r in /in/V0qRW on line 3 Notice: Undefined index: model in /in/V0qRW on line 4 <html> <head> <title>Fungsi Permutasi dengan PHP</title> </head> <body> <center> <form method="post"> <table cellpadding=5 cellspacing=2 border=1> <tr> <td>Permutasi</td> <td> <select name="model"> <option value="ulang">Permutasi Perulangan</option> <option value="tidak">Permutasi Tak Berulang</option> </select> </td> </tr> <tr> <td>N</td> <td><input type=text name="n" size=5 value=<? echo $n; ?> /></td> </tr> <tr> <td>M</td> <td><input type=text name="r" size=5 value=<? echo $r; ?> /></td> </tr> <tr> <td colspan=2 align=center><input type="submit" value="Permutasi" /></td> </tr> </table> </form> </center> </body> </html>
Output for 4.3.0 - 5.2.17
Notice: Undefined index: n in /in/V0qRW on line 2 Notice: Undefined index: r in /in/V0qRW on line 3 Notice: Undefined index: model in /in/V0qRW on line 4 <html> <head> <title>Fungsi Permutasi dengan PHP</title> </head> <body> <center> <form method="post"> <table cellpadding=5 cellspacing=2 border=1> <tr> <td>Permutasi</td> <td> <select name="model"> <option value="ulang">Permutasi Perulangan</option> <option value="tidak">Permutasi Tak Berulang</option> </select> </td> </tr> <tr> <td>N</td> <td><input type=text name="n" size=5 value=<? echo $n; ?> /></td> </tr> <tr> <td>M</td> <td><input type=text name="r" size=5 value=<? echo $r; ?> /></td> </tr> <tr> <td colspan=2 align=center><input type="submit" value="Permutasi" /></td> </tr> </table> </form> </center> </body> </html>