W
worlman385
what are the difference of below 2 factorial function?
the 1st return 0;
the 2nd return factorial result;
what 's the problem of 1st one?
sub factorial
{
$number = $_[0];
if ( $number == 0 ) {
1;
}
else {
$number * factorial( $number - 1 );
}
}
sub factorial
{
if ($_[0] == 0) {
1;
}
else {
$_[0] * factorial($_[0]-1);
}
}
the 1st return 0;
the 2nd return factorial result;
what 's the problem of 1st one?
sub factorial
{
$number = $_[0];
if ( $number == 0 ) {
1;
}
else {
$number * factorial( $number - 1 );
}
}
sub factorial
{
if ($_[0] == 0) {
1;
}
else {
$_[0] * factorial($_[0]-1);
}
}