fork(4) download
  1. program Foo;
  2.  
  3. {$MODE OBJFPC}{$LONGSTRINGS ON}
  4.  
  5. function SecondLargest(const AVector: array of Integer): Integer;
  6. var
  7. Second: Integer absolute Result;
  8. Largest, Value: Integer;
  9. begin
  10. Second := 0;
  11. Largest := 0;
  12.  
  13. for Value in AVector do
  14. if Value > Largest then
  15. begin
  16. Second := Largest;
  17. Largest := Value;
  18. end
  19. else
  20. if Value > Second then
  21. Second := Value;
  22. end;
  23.  
  24. begin
  25. Write('Second Largest: ', SecondLargest([3, 1, 2, 7, 2, 8, 6]));
  26. end.
Success #stdin #stdout 0s 336KB
stdin
Standard input is empty
stdout
Second Largest: 7