Interview Questions

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

Electrical Engineering Technical Interview Questions and Answers


(Continued from previous question...)

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

// BEGIN PERL SNIPET

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

// END PERL SNIPET

(Continued on next question...)

Other Interview Questions