Если лень перебирать вручную, можно воспользоваться программой
var k,l,r,x,f:integer; begin f := 3001; l := 0; r := 65534; x := (l + r) div 2; k := 1; while (x <> f) and (l < r) do begin writeln(k,' ',l,' ',r,' ',x); k := k + 1; if f < x then r := x - 1 else l := x + 1; x := (l + r) div 2 end; writeln(k,' ',l,' ',r,' ',x); end.
Var N:Array[1..20] of integer; i,j,q,k,max:integer;begin Randomize;writeln('массив');for i:=1 to 20 do beginN[i]:= random(100)-50;write(N[i]:4);end;writeln;i:=0;writeln('Измененый массив');While j<20 do beginj:= j + 2; k := N[j-1];N[j-1]:=N[j]; N[j]:= k;end;foreach q in N do beginwrite(q :4);end;end. var N,M:Array[1..20] of integer; i,j,min,q,k,max:integer;begin Randomize;max:=-200; min:=200;writeln('1 массив');for i:=1 to 20 do beginN[i]:= random(100)-50;write(N[i]:4);if ((N[i]>0 )and(N[i] mod 2 = 0))then beginif max < N[i] then max := N[i];if min > N[i] then min := N[i];j:= j + 1;M[j]:=N[i];end;end;writeln;writeln('2 массив');foreach k in M do beginwrite(k:4);end;writeln;if (max = -200) or (min = 200) then write ('нет чётных положительных элементов')else beginwrite('max = ' ,max:4);write(' min = ' ,min:4);end;end.
1. 0..65534 -> 32767
2. 0..32766 -> 16383
3. 0..16382 -> 8191
4. 0..8190 -> 4095
5. 0..4094 -> 2047
6. 2048..4094 -> 3071
7. 2048..3070 -> 2559
8. 2560..3070 -> 2815
9. 2816..3070 -> 2943
10. 2944..3070 -> 3007
11. 2944..3006 -> 2975
12. 2976..3006 -> 2991
13. 2992..3006 -> 2999
14. 3000..3006 -> 3003
15. 3000..3002 -> 3001
Если лень перебирать вручную, можно воспользоваться программой
var k,l,r,x,f:integer;
begin
f := 3001;
l := 0;
r := 65534;
x := (l + r) div 2;
k := 1;
while (x <> f) and (l < r) do
begin
writeln(k,' ',l,' ',r,' ',x);
k := k + 1;
if f < x then r := x - 1
else l := x + 1;
x := (l + r) div 2
end;
writeln(k,' ',l,' ',r,' ',x);
end.
var N,M:Array[1..20] of integer; i,j,min,q,k,max:integer;begin Randomize;max:=-200; min:=200;writeln('1 массив');for i:=1 to 20 do beginN[i]:= random(100)-50;write(N[i]:4);if ((N[i]>0 )and(N[i] mod 2 = 0))then beginif max < N[i] then max := N[i];if min > N[i] then min := N[i];j:= j + 1;M[j]:=N[i];end;end;writeln;writeln('2 массив');foreach k in M do beginwrite(k:4);end;writeln;if (max = -200) or (min = 200) then write ('нет чётных положительных элементов')else beginwrite('max = ' ,max:4);write(' min = ' ,min:4);end;end.