Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

Algorithms/Find maximum/perl method 1

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

perl source code sub findmax() { return 0 if $#_ == -1; return $_[0] if $#_ == 0; my $curr_max = $_[0]; foreach (@_) { $curr_max = $_ if $_ > $curr_max; } return $curr_max; } Simple example of using this subroutine: print &findmax(qw /1 5 3 199 2/); output should be: 199