Должно работать:
program prim;
var a: array[0..99999] of integer;
i:byte;
f:integer;
b,c:integer;
begin
for i:=0 to 99999 do begin
readln(a[i]);
if a[i]=0 then break;
f:=i;
end;
for i:=0 to f do begin
if a[i]>c then begin
if a[i]>b then b:=a[i] else c:=a[i];
end;end;
writeln(b, ' ',c);
end.