Electrical Engineering Question:

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

Electrical Engineering Interview Question
Electrical Engineering Interview Question

Answer:

Examples: Input is 5 Input is 7

<pre>
* *
*** ***
***** *****
*** *******
* *****
***
*

</pre>
### 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 ###


Previous QuestionNext Question
Write a function to determine whether a string is a palindrome (same forward as reverse, such as "radar" or "mom")Given the following FIFO and rules, how deep does the FIFO need to be to prevent underflowing or overflowing?