Locate common interval from more intervals
Delphi & Pascal (česká wiki)
Category: Homework in Pascal
Program: Interval.pas
File exe: Interval.exe
Program: Interval.pas
File exe: Interval.exe
Locate common interval from more intervals.
{ INTERVAL.PAS Copyright (c) TrSek alias Zdeno Sekerak } { Zistite, ci v danych intervalov ma spolocny bod. } { priklad: pocet intervalov=3 } { x[1]=1, y[1]=6, x[2]=2, y[2]=8, x[3]=4, y[3]=9 } { vysledok <4,6> } { } { Datum:23.05.2004 http://www.trsek.com } program intevaly; const MAX=100; var poc:integer; { pocet intevalov } x:array[1..MAX] of real; { zaciatok intevalov } y:array[1..MAX] of real; { koniec intevalov } zac,kon:real; { zaciatok a koniec prieniku intervalov } i:integer; begin WriteLn('Zistenie spolocneho intervalu.'); Write('Zadaj pocet intevalov (max=',MAX,'):'); ReadLn(poc); WriteLn('Zadavaj krajne body intervalov x-y'); for i:=1 to poc do begin Write('x[',i,']='); ReadLn(x[i]); Write('y[',i,']='); ReadLn(y[i]); end; { pociatocny inteval } zac:=x[i]; kon:=y[i]; { bude robit postupne prieniky } for i:=1 to poc do begin if(x[i]>zac)then zac:=x[i]; if(y[i]<kon)then kon:=y[i]; end; WriteLn('Prienik intervalov je <',zac:0:3,',',kon:0:3,'>'); ReadLn; end.