Interview Questions Answers.ORG
Interviewer And Interviewee Guide
Interviews
Quizzes
Home
Quizzes
Interviews Best Engineering Interviews:Aeronautical EngineeringAgricultural EngineeringApplied EngineeringAssociate EngineeringAutomobile EngineeringBio EngineeringBiomedical EngineerBiomedical EngineeringBuilding Services EngineeringCAD/CAE EngineerChemical EngineeringCivil EngineeringDAE Knitting EngineersDeputy Chief Financial OfficerDesktop EngineerDiesel MechanicElectrical EngineeringElectronics CommunicationsElectronics EngineeringEmbedded Software EngineerEnergy EngineeringEnergy Oil GasEngineeringGalvanizing EngineerIndustrial EngineeringInstrumentation EngineeringLaptop RepairerMachine Learning EngineerMachine OperatorMarine EngineeringMechanical EngineeringMechatronics EngineeringNetwork EngineerNuclear EngineeringPetroleum EngineeringPlant Reliability EngineerPlumberPre EngineeringProduction EngineerRF EngineerSystem EngineeringTextile Engineer
Copyright © 2018. All Rights Reserved
Electrical Engineering Interview Question:
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
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.
https://InterviewQuestionsAnswers.ORG.