Advertisement
avukas

Peti tut, 5.zad

Mar 28th, 2015
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. bool f(int x, int n)
  5. {
  6.     if (x<n) return true;
  7.     return false;
  8. }
  9.  
  10.  
  11.  
  12. int main()
  13. {
  14.     int niz[50] {1,2,5,8,7,9,6,4,5,12,23,11,56,16,18,20,17,18,2,21,22,24,26,28,27,22,34,26,
  15.                  99,88,77,44,55,66,33,22,11,44,2,1,55,4,111,22,12,87,82,45,63,52
  16.                 };
  17.     int n;
  18.  
  19.     std::sort(niz, niz+50);
  20.     for(int x : niz)
  21.  
  22.         std::cout << x << " " ;
  23.     std:: cout << std::endl;
  24.  
  25.     std::cout<<"Unesi n:\n ";
  26.     std::cin>>n;
  27.  
  28.     if(std::binary_search(niz, niz+50 , n)){
  29.         std::cout << "ima u nizu ";
  30.         int *pok = std::lower_bound(niz, niz+50 , n);
  31.  
  32.         std::cout << " i nalazi se na: "<< pok - niz;
  33.     }
  34.     else std::cout << "nije u nizu ";
  35.  
  36.  
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement