josiftepe

Untitled

Nov 15th, 2020
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. int main()
  7. {
  8.     int N;
  9.     cin >> N;
  10.     int niza[N];
  11.     for(int i = 0; i < N; i += 1) {
  12.         cin >> niza[i];
  13.     }
  14.     for(int i = 0; i < N; i += 1) {
  15.         for(int j = i + 1; j < N; j += 1) { // za sekoj element niza[i], pomini gi site broevi sto se desno od nego. Prviot broj desno od nego e i + 1 i zatoa j = i + 1
  16.             if(niza[i] > niza[j]) {
  17.                 swap(niza[i], niza[j]);
  18.                 // A = 5, B = 10
  19.                 // swap(A, B)
  20.                 // A = 10, B = 5
  21.             }
  22.            
  23.         }
  24.     }
  25.     for(int i = 0; i < N; i += 1) {
  26.         cout << niza[i] << " ";
  27.     }
  28.  
  29.     return 0;
  30. }
  31. /*
  32.  
  33.  1 2 3 5 6 7 9
  34.  
  35.  */
  36.  
Advertisement
Add Comment
Please, Sign In to add comment