Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
binary_search-бинарный_поиск
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
{Двоичный (бинарный поиск)} const n = 4; var a: array[0..n] of integer; low, high, mid, d: integer; i: integer; begin for i := 0 to n do begin a[i] := 2*i+1; write (a[i], ' ') end; writeln; readln(d); low := 0; high := n; while low <= high do begin mid := (high + low) div 2; if a[mid] = d then begin writeln(mid); low := high; end else if a[mid] > d then high := mid-1 else low := mid+1 end; writeln (low, ' ', high) end.
Show compiler warnings
[
+
]
Show input
edit mode
|
history
|
discussion