PDA

View Full Version : Using perl code.



DemonixX
August 19th, 2009, 06:57 AM
How would one go about finding the greatest number in an array of numbers using loops and if statements? For example, if you had an array like this:

(4, 8, 3, 19, 6, 11)

jwilliam
August 28th, 2009, 12:15 PM
This would work:



@array = (4, 8, 3, 19, 6, 11);
$max = -1;

foreach(@array) {
if($_ > $max) {
$max = $_;
}
}

print $max . "\n";