Last active
June 7, 2018 07:01
-
-
Save niravmadariya/bbb7cea761234388f6f7683ab24010a4 to your computer and use it in GitHub Desktop.
Factorial Program in php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Factorial Program using loop in PHP</title> | |
</head> | |
<body> | |
<form method="post"> | |
Enter the Number:<br> | |
<input type="number" name="number" id="number"> | |
<input type="submit" name="submit" value="Submit" /> | |
</form> | |
<?php | |
if($_POST['submit']){ | |
$fact = 1; | |
//getting value from input text box 'number' | |
$number = $_POST['number']; | |
echo "Factorial of $number:<br><br>"; | |
//start loop | |
for ($i = 1; $i <= $number; $i++){ | |
$fact = $fact * $i; | |
} | |
echo $fact . "<br>"; | |
} | |
?> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>Factorial Program using loop in PHP</title> | |
</head> | |
<body> | |
<form method="post"> | |
Enter the Number:<br> | |
<input type="number" name="number" id="number"> | |
<input type="submit" name="submit" value="Submit" /> | |
</form> | |
<?php | |
if($_POST['submit']){ | |
function fact ($n) | |
{ | |
if($n <= 1) | |
{ | |
return 1; | |
} | |
else | |
{ | |
return $n * fact($n - 1); | |
} | |
} | |
echo "Factorial of $_POST['number'] is " .fact($_POST['number']); | |
} | |
?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment