PHP Programs

Please click on 1-2 Ads to keep this website's Study Material FREE and regularly Updated.

Program 1: Write a function to calculate the factorial of a number (non-negative integer). The function accept the number as an argument.


<!DOCTYPE html>
	<title>PHP Programs</title>
	<form name="Factorial Calculator" method="POST" action="">
		Enter any number to calculate factorial
		<input type="text" name="input"><br/>
		<input type="submit" name="submit" value="Calculate">

		if(isset($_POST["submit"]) == "Calculate")
			$fact = calculate_factorial($number);
			echo"<br/> Factorial of $number is $fact";

		function calculate_factorial($num)
			$factorial = 1;

			for($x=$num; $x>=1; $x--)
			return $factorial;

If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.