Habsburg

1. novi

May 18th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.47 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 * A = new float[N];
  10.     for(int i = 0; i < N; i++) {
  11.         cout << "Broj: ";
  12.         cin >> A[i];
  13.     }
  14.     int max = 0;
  15.     for(int i = N-1; i >= 1; i--) {
  16.         max = i;
  17.         for(int j = 0; j < i; j++)
  18.             if(A[j] < A[max])
  19.                 max = j;
  20.         float pom = A[i];
  21.         A[i] = A[max];
  22.         A[max] = pom;
  23.     }
  24.    
  25.     for(int i = 0; i < N; i++)
  26.         cout << A[i] << endl;
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment