Well, today my sister was working doing her homework and, she kind of got stressed with it, so she called me and, I ended up making it for her… I learned what a factorial is and, made this nice little function that finds the factorial of any number you pass to it. It was supposed to be written in labview, but I don’t really know what that is… so I used php xD It worked like a charm in labview according to my sister. so you can also use it in labview I guess :O
1 2 3 4 5 6 7 8 9 | <?php function factorial($input){ $output = 1; for($x = $input; $x >= 1; $x--){ $output *= $x; } return($output); } ?> |
I made an example of this function’s usage using JavaScript, check it out here
#1 by Tim Cooper at August 8th, 2009
| Quote
function factorial($n){
return $n == 1 ? 1:$n * factorial($n – 1);
}
#2 by Seich at August 8th, 2009
| Quote
My sister was required to use a for loop ^^ plus idk what labview’s capabilities are so, I kept it as basic as possible. I like your function nevertheless, it is short and simple.
#3 by mutsil at October 8th, 2009
| Quote
how to get input for the same function.
#4 by Seich at October 8th, 2009
| Quote
what do you mean?
#5 by Mutsil at October 9th, 2009
| Quote
can you explain it with the help of getting input with a form by post method..
Here can u please give me a page “process.php” with a code getting input.
#6 by Seich at October 9th, 2009
| Quote
something like this would get the information from a form and then have it echo the factorial.
process.php
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$f = $_POST['factorial'];
echo(factorial($f));
function factorial($input){
$output = 1;
for($x = $input; $x >= 1; $x--){
$output *= $x;
}
return($output);
}
?>
I hope that fulfills your request.