4. The factorial of a number, N, is defined as follows: N! 1 * 2 * 3 * 4 *. . .
ID: 655351 • Letter: 4
Question
4. The factorial of a number, N, is defined as follows: N! 1 * 2 * 3 * 4 *. . . . . * N Forexample,4! 4 * 3 * 2 * land 7! = 7 * 6 * 5 * 4 * 3 * 2 * 1 Create a web page that allows the user to enter a positive integer and the page will display the factorial of that number. Hint: Use a variable, factorial, with an initial value of 1. 1?hen use a loop to multiply factorial 1w successive integers up (() the value entered by the user. Save your page as factorial . html and be sure to include an appropriate page title.Explanation / Answer
?php
/* Function to get Factorial of a Number */
function getFactorial($num)
{
$fact = 1;
for($i = 1; $i <= $num ;$i++)
$fact = $fact * $i;
return $fact;
}
?>
<!doctype html>
<html>
<head>
<title>Factorial</title>
</head>
<body>
<form action = "" method="post">
Enter the number whose factorial requires <Br />
<input type="number" name="number" id="number" maxlength="4" autofocus required/>
<input type="submit" name="submit" value="Submit" />
</form>
<?php
if(isset($_POST['submit']) and $_POST['submit'] == "Submit")
{
if(isset($_POST['number']) and is_numeric($_POST['number']))
{
echo 'Factorial Of Number: <strong>'.getFactorial($_POST['number']).'</strong>';
}
}
?>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.