Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- cout << "Zamisli eden broj od 1 do 1000, i ne mi go kazuvaj" << endl;
- cout << "So maksimum 11 prasanja ke go pogodam brojot" << endl;
- int L = 1, R = 1000;
- while(L <= R) {
- int middle = (L + R) / 2;
- cout << "Vnesi 0 ako " << middle << " e tvojot zamislen broj, vnesi -1 ako e pomal od " << middle << ", ili vnesi 1 ako e pogolem od " << middle << endl;
- int x;
- cin >> x;
- if(x == 0) {
- cout << "Tvojot broj e " << middle << ". Kraj na igrata!" << endl;
- break;
- }
- else if(x == -1) {
- R = middle - 1;
- }
- else {
- L = middle + 1;
- }
- }
- return 0;
- }
- // 972
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement