Habsburg

2.

May 18th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 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.     bool found = true;
  15.     while(found) {
  16.         found = false;
  17.         for(int i = 0; i < N-1; i++) {
  18.             if(polje[i] > polje[i+1]) {
  19.                 swap(polje[i], polje[i+1]);
  20.                 found = true;
  21.             }
  22.         }
  23.        
  24.     }
  25.    
  26.     for(int i = 0; i < N; i++)
  27.         cout << polje[i] << endl;
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment