Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <algorithm>
- using namespace std;
- int main()
- {
- int n;
- cin >> n;
- int a[n];
- for(int i = 0; i < n; i++) {
- cin >> a[i];
- }
- int x;
- cin >> x;
- int L = 0;
- int R = n - 1;
- while(L <= R) {
- int middle = (L + R) / 2;
- if(a[middle] < x) {
- L = middle + 1;
- }
- else if(a[middle] > x) {
- R = middle - 1;
- }
- else if(a[middle] == x) {
- cout << "Ovoj broj postoi vo nizata" << endl;
- return 0;
- }
- }
- cout << "Ne postoi" << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement