Write a function to output a diamond shape according to the given (odd) input?

Submitted by: Administrator
Examples: Input is 5 Input is 7


* *
*** ***
***** *****
*** *******
* *****
***
*


### 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--) { print "*"; }
}
print "n";
}
### END PERL SNIPET ###
Submitted by: Administrator

Read Online Electrical Engineering Job Interview Questions And Answers