Advertisement
zuky777

PRVI

May 25th, 2015
258
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. using namespace std;
  3.  
  4. void Sort_izborom(int* polje, int n) {
  5.     for(int i=n, j; i>0; i--) {
  6.         int maxi = 0;
  7.         for(j=0; j<i; j++)
  8.             if(polje[maxi]>polje[j]) maxi=j;
  9.         int pom = polje[i-1];
  10.         polje[i-1] = polje[maxi];
  11.         polje[maxi] = pom;
  12.     }
  13. }
  14. int func_i_ti_broj(int* polje, int n, int i) {
  15.     Sort_izborom(polje, n);
  16.     return polje[i];
  17. }
  18.  
  19. int main() {
  20.     int N, I;
  21.     do {
  22.         cout << "N = ";
  23.         cin >> N;
  24.     } while(N<1);
  25.    
  26.     do {
  27.         cout << "I = ";
  28.         cin >> I;
  29.     } while(I<0 || I>=N);
  30.    
  31.     int polje[N];
  32.     for(int i=0; i<N; i++)
  33.         cin >> polje[i];
  34.     int rj = func_i_ti_broj(polje, N, I);
  35.     cout << rj << endl;
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement