program x3;
uses crt;
const n=20;
var m: array [1..n] of integer;
found: boolean;
a,i,fst,lst: integer;
k,j: integer;
begin
clrscr;
randomize;
begin
for i:=1 to n do
m[i]:=random(20);
for i:=1 to n do
write(m[i],' ');
readln;
begin
for i:=2 to n do
for j:=n downto i do
if m[j-1]<m[j] then begin
k:=m[j]; m[j]:=m[j-1];
m[j-1]:=k;
end;
end;
end;
write('otsortirovan:');readln;
for i:=1 to n do
write(m[i],' ');
readln;
writeln('vvedite chislo ot 0 do 20'); readln(a);
begin
fst:=1; lst:=n; found:=false;
repeat
i:=(fst+lst) div 2;
if m[i]=a then found:=true
else if m[i]<a then fst:=i+i
else lst:=i-1
until(found) or (fst>lst); end;
if found=true then writeln ('nomer iskomogo elementa',i)
else writeln('takogo net');
readln;
end.
Про теги не забывай
Сообщение отредактировано: volvo -