Advertisement
Josif_tepe

Untitled

Mar 31st, 2024
794
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. // 971
  6. int main() {
  7.     cout << "Zamislete broj od 1 do 1000, i ke go pogodime vo 11 prasanja" << endl;
  8.    
  9.     int L = 1, R = 1000;
  10.     while(L <= R) {
  11.         int middle = (L + R) / 2;
  12.         cout << "Ako vasiot broj e ednakov na " << middle << " vnesete 0, ako e pomal vnesete -1, a ako e pogolem vnesete 1" << endl;
  13.         int x;
  14.         cin >> x;
  15.        
  16.         if(x == 0) {
  17.             cout << "Vashiot broj e ednakov na " << middle << endl;
  18.             break;
  19.         }
  20.         else if(x == 1) {
  21.             L = middle + 1;
  22.         }
  23.        
  24.         else {
  25.             R = middle - 1;
  26.         }
  27.     }
  28.    
  29.     return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement