Monday, September 19, 2016

Factorial Program Using Functions in PERL

A simple factorial program that uses Functions in Perl that will ask the user to give a number and then our program will compute the factorial value based on the given number by our user.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.
 
My mobile number here in the Philippines is 09173084360
.


Program Listing

#!D:\xampp\perl\bin

sub factorial {
  my($num) = @_;
  if ($num == 1) {
    return 1;   
  } else {
    return $num*factorial($num - 1);  
  }
}

print "Factorial Program in Perl";
print "\n";
print "Enter a Number : ";
$number = <>;
chop ($number); 
print "\n";
print factorial($number);

No comments:

Post a Comment