function factorial_integer ($k)
{
//variable and initializations
$the_result = 1;
//check to see if k is an integer
if (!is_int($k))
{
return "error";
}
//check for k < 0
if ($k < 0)
{
return "error";
}
//0! = 1
if ($k == 0)
{
return 1;
}
//calculate the result
for ($i = 2; $i <= $k; $i++)
{
$the_result = $the_result * $i;
}
//return the value
return $the_result;
} |