Factorial of a number in PHP

Advertisements

Prev Tutorial Next Tutorial

Factorial of a number in PHP

In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. But here we write program; how to print factorial of any number in php.

Example of Factorial

	
5!= 5 * 4 * 3 * 2 * 1 = 120

Factorial of a number in PHP

<?php

$num = 4;
$factorial = 1;
for ($x=$num; $x>=1; $x--) 
{
  $factorial = $factorial * $x;
}
echo "Factorial of $num is $factorial";

?>

Output

	
Factorial of 4 is 24

Prev Tutorial Next Tutorial

Advertisements

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 9999595223

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

Download Projects

Google Advertisements


Buy Websites 9999595223

Buy College Projects with Documentation Contact on whatsapp 9999595223. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements