# File: factrec.pl # Title: FACTORIAL n! RECURSIVE # Use subroutine. Input from keyboard an integer. Compute factorial # Do this until you want to. Continue(y/n)? # Author: Mihaela Malita # Input number? 5 # Result: 5! = 120 # Continue(y/n)? n # Bye $yesorno = 'y'; while($yesorno eq 'y') { print "Input number? "; $n = ; chop($n); #read n print "Result: $n ! = $r",fact($n); # invoke subroutine fact($n) print "\nContinue(y/n)? "; #ask if more $yesorno = ; chop($yesorno); } print "Bye"; exit; sub fact { my($n) = @_; #n is local variable if ($n == 1) {return 1;} # 1! = 1 else {return (fact($n-1) * $n );} # n! = n * (n-1)! }