Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,844 questions

51,765 answers

573 users

How to find the second biggest number in a set of random numbers in Pascal

1 Answer

0 votes
program SecondMaxFinder;

function FindSecondMax(total, rndmax: integer): integer;
var
  max, before_max, n, i: integer;
begin
  randomize;
  n := random(rndmax) + 1;
  writeln(n);
  max := n;
  before_max := n;

  for i := 1 to total - 1 do
  begin
    n := random(rndmax) + 1;
    writeln(n);
    if n > max then
    begin
      before_max := max;
      max := n;
    end
    else if n > before_max then
      before_max := n;
  end;

  FindSecondMax := before_max;
end;

var
  secondMax: integer;

begin
  secondMax := FindSecondMax(10, 100);
  writeln('The second biggest number is: ', secondMax);
end.




(*
run:

43
81
75
94
36
42
93
53
68
49
The second biggest number is: 93

*)


 



answered Oct 4, 2025 by avibootz
...