Habsburg

5.

May 25th, 2015
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void SelSort(int polje[], int num) {
  5.     for(int i = num - 1; i > 0; i-- )
  6.         for(int j = 0; j < i; j++)
  7.             if(polje[j] > polje[j+1])
  8.                 swap(polje[j], polje[j+1]);
  9. }
  10. void NajBroj(int polje[], int num) {
  11.     int i;
  12.     cout << "i: ";
  13.     cin >> i;
  14.     if(i >= num)
  15.         return;
  16.     cout << polje[num - i] << endl;
  17. }
  18.  
  19. int main() {
  20.     int N;
  21.     do{
  22.         cout << "Upisite N: ";
  23.         cin >> N;
  24.     }while( N < 0);
  25.     int polje[N];
  26.     for(int i = 0; i < N; i++) {
  27.         cout << i+1 << ": ";
  28.         cin >> polje[i];
  29.     }
  30.     SelSort(polje, N);
  31.     for(int i = 0; i < N; i++) {
  32.         cout << polje[i] << " ";
  33.     }
  34.     cout << endl;
  35.     NajBroj(polje, N);
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment