Electrical Engineering Question:

Write the code for finding the factorial of a passed integer. Use a recursive subroutine?

Electrical Engineering Interview Question
Electrical Engineering Interview Question

Answer:

// BEGIN PERL SNIPET

sub factorial {
my $y = shift;
if ( $y > 1 ) {
return $y * &factorial( $y - 1 );
} else {
return 1;
}
}

// END PERL SNIPET


Previous QuestionNext Question
Write the code to sort an array of integers?In C, explain the difference between the & operator and the * operator?