Q: Write The Code For Finding The Factorial of A Passed Integer. Use A Recursive Subroutine
Q: Write The Code For Finding The Factorial of A Passed Integer. Use A Recursive Subroutine
Q: Write the code for finding the factorial of a passed integer. Use a recursive subroutine. A: // BEGIN PERL SNIPET sub factorial { my $y = shift; if ( $y > 1 ) { return $y * &factorial( $y - 1 ); } else { return 1; } } // END PERL SNIPET
Q: Given $a = "5,-3,7,0,-5,12"; Write a program to find the lowest number in the string. A: // BEGIN PERL SNIPET $a = "5,-5,-1,0,12,-3"; (@temp) = split (/,/, $a); $lowest = $temp[0]; for ($i=0; $i<6; $i++) { if ($temp[$i] < $lowest)
{ $lowest = $temp[$i]; } } print "Lowest value found was: $lowest\n"; // END PERL SNIPET NOTE: You could also replace the for loop with this: foreach $value (@temp) { if ($value < $lowest) { $lowest = $value; } }
Q: Write a function to output a diamond shape according to the given (odd) input. Examples: Input is 5 * *** ***** *** * Input is 7 * *** ***** ******* ***** *** *
A: ### BEGIN PERL SNIPET ### for ($i = 1; $i <= (($input * 2) - 1); $i += 2) { if ($i <= $input) { $stars = $i; $spaces = ($input - $stars) / 2; while ($spaces--) { print " "; } while ($stars--) { print "*"; } } else { $spaces = ($i - $input) / 2; $stars = $input - ($spaces * 2); while ($spaces--) { print " "; } while ($stars--) {
Read more: http://vlsiquestions.webnode.com/perl/ Create your own website for free: http://www.webnode.com