Write recursive subroutines : Recursive « Subroutine « Perl






Write recursive subroutines

   
    sub Factorial {
        my($n) = @_;

        $n <= 2 and return $n;
        return $n * Factorial($n-1);
    }

    for $i (1..9) {
        print "$i Factorial =\t", Factorial($i), "\n";
    }

   
    
    
  








Related examples in the same category

1.Recursive factorial subroutine
2.Recursive fibonacci function.
3.Recursive subroutine
4.calculate 1000th element of standard Fibonacci sequence
5.factorial with recursive function
6.A recursive subroutine to perform arithmetic.