Advertisement
amermo

TP T-4 Z5

Mar 31st, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. int main()
  5. {
  6.     int niz[10] {1, 3, 5, 7, 9, 10, 8, 6, 4, 2}, n;
  7.     std::sort(niz, niz+10);
  8.     std::cout << "Unesite n: ";
  9.     std::cin >> n;
  10.     if(std::binary_search(niz, niz+10, n))
  11.         std::cout << "Element " << n << " se nalazi na " << std::lower_bound(niz, niz+10, n) - niz + 1 << " poziciji!";
  12.     else
  13.         std::cout << "Element " << n << " nije nadjen!";
  14.     return 0;
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement