Interview Questions

Given $a = "5,-3,7,0,-5,12"; Write a program to find the lowest number in the string.

Electrical Engineering Technical Interview Questions and Answers


(Continued from previous question...)

9. Given $a = "5,-3,7,0,-5,12"; Write a program to find the lowest number in the string.

// 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; }
}

(Continued on next question...)

Other Interview Questions