[ create a new paste ] login | about

Link: http://codepad.org/1Zq1q4zH    [ raw code | output | fork ]

Perl, pasted on Sep 26:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@arr = (1, 3, 2, 10, 9);

$max1 = $max2 = $arr[0];

for my $i (@arr){

   if($i > $max1){
      $max2 = $max1;
      $max1 = $i;
   }
   elsif($i > $max2){
      $max2 = $i;
   }
}

print "Max1: $max1, Max2: $max2\n";


Output:
1
Max1: 10, Max2: 9


Create a new paste based on this one


Comments: