$n1=50; // change this number
for($i=1;$i<=($n1/2); $i++){
if($n1%$i == 0 )
echo " $i," ;
}
echo $n1 ;
$n1=5; // change this number
$factorial=1;
for ($i=1; $i<=$n1;$i++){
$factorial=$factorial*$i;
}
echo "Factorial of $n1 : $factorial";
Output
Factorial of 5 : 120
$n1=$_POST['n1'];
echo "<form method=POST action=''>
<input type=text name=n1 value='$n1'>
<input type=submit value=Submit>
</form>";
$factorial=1;
for ($i=1; $i<=$n1;$i++){
$factorial=$factorial*$i;
}
echo "Factorial of $n1 : $factorial";

function fact($n){
if($n<>1){
$factorial = $n * fact($n-1);
return $factorial;
}else{
return 1;
}
}
echo "Factorial of 6 : ".fact(6);
Output is here
Factorial of 6 : 720
Introduction to PHP Sum of digits of a number
Strong Number
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.