Habsburg

1.

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