fork download
  1. int l = 0;
  2. int r = 1000;
  3. int x = 1000;
  4. // l and r denote our current bounds: we know that l <= x <= r
  5. while(l<r) {
  6. // we will ask about the number in the middle
  7. int m = (l+r)/2;
  8. // note: this is an integer division, thus e.g., for l=0, r=1 we get m=1/2=0
  9. if(x <= m)
  10. r = m;
  11. else
  12. l = m+1;
  13. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:5:1: error: expected unqualified-id before ‘while’
 while(l<r) {
 ^~~~~
stdout
Standard output is empty