Factorial, in arithmetic, the product of all optimistic integers lower than or equal to a given optimistic integer and denoted by that integer and an exclamation level. Thus, factorial seven is written 7! that means 1 × 2 × 3 × 4 × 5 × 6 × 7. Factorial zero is outlined as equal to 1.
In programming, a recursive perform is a perform that calls itself when it’s executed. This permits the perform to repeat itself a number of occasions, producing the outcome on the finish of every replication.
Right here is the Instance
<!DOCTYPE html>
<html>
<head>
<meta charset=”utf-8″>
<meta identify=”viewport” content material=”width=device-width, initial-scale=1″>
<title>factorial-recursive-function</title>
</head>
<physique>
<h4>Factorial of a Given Quantity utilizing Recursive perform</h4>
<hr />
<!— PHP Code –>
<?php
if(isset($_POST[‘submit’])){
perform truth($n){
if($n <= 1){
return 1;
}
else{
return $n * truth($n – 1);
}
}
$n =$_POST[‘number’]; // Enter Quantity
$f = truth($n);
echo “Factorial of $n is $f”;
}
?>
<kind methodology=”submit”>
<p>Enter the Quantity </p>
<enter kind=”textual content” identify=”quantity” required>
<enter kind=”submit” identify=”submit”>
</kind>
</physique>
</html>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
<!DOCTYPE html> <html> <head> <meta charset=“utf-8”> <meta identify=“viewport” content material=“width=device-width, initial-scale=1”> <title>factorial–recursive–perform</title> </head> <physique> <h4>Factorial of a Given Quantity utilizing Recursive perform</h4> <hr /> <!—– PHP Code —> <?php if(isset($_POST[‘submit’])){ perform truth($n){ if($n <= 1){ return 1; } else{ return $n * truth($n – 1); } } $n =$_POST[‘number’]; // Enter Quantity $f = truth($n); echo “Factorial of $n is $f”; } ?>
<kind methodology=“submit”> <p>Enter the Quantity </p> <enter kind=“textual content” identify=“quantity” required> <enter kind=“submit” identify=“submit”> </kind>
</physique> </html> |
You may additionally like…