Electrical Engineering Question:
Write the code for finding the factorial of a passed integer. Use a recursive subroutine?

Answer:
// BEGIN PERL SNIPET
sub factorial {
my $y = shift;
if ( $y > 1 ) {
return $y * &factorial( $y - 1 );
} else {
return 1;
}
}
// END PERL SNIPET
sub factorial {
my $y = shift;
if ( $y > 1 ) {
return $y * &factorial( $y - 1 );
} else {
return 1;
}
}
// END PERL SNIPET
Previous Question | Next Question |
Write the code to sort an array of integers? | In C, explain the difference between the & operator and the * operator? |