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