Write a function to output a diamond shape according to the given (odd) input?
Submitted by: AdministratorExamples: 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 ###
Submitted by: Administrator
<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 ###
Submitted by: Administrator
Read Online Electrical Engineering Job Interview Questions And Answers
Top Electrical Engineering Questions
☺ | CO2 fire extinguishers are indicated by the color code |
☺ | In a star connected three phase transformer the |
☺ | A single-phase double-wound transformer consists of |
☺ | A residual current device will disconnect under |
☺ | The usual method of insulating core laminations is |
Top Best Engineering Categories
☺ | Mechanical Engineering Interview Questions. |
☺ | Civil Engineering Interview Questions. |
☺ | Chemical Engineering Interview Questions. |
☺ | Electrical Engineering Interview Questions. |
☺ | Automobile Engineering Interview Questions. |