fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int l = 0;
  7. int r = 1000;
  8. // l and r denote our current bounds: we know that l <= x <= r
  9. while(l<r) {
  10. // we will ask about the number in the middle
  11. int m = (l+r)/2;
  12. // note: this is an integer division, thus e.g., for l=0, r=1 we get m=1/2=0
  13. if(x <= m)
  14. r = m;
  15. else
  16. l = m+1;
  17. }
  18. cout << m;
  19. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:13:7: error: ‘x’ was not declared in this scope
    if(x <= m)
       ^
prog.cpp:18:12: error: ‘m’ was not declared in this scope
    cout << m;
            ^
stdout
Standard output is empty