Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int N;
- cin >> N;
- int niza[N];
- for(int i = 0; i < N; i += 1) {
- cin >> niza[i];
- }
- for(int i = 0; i < N; i += 1) {
- 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
- if(niza[i] > niza[j]) {
- swap(niza[i], niza[j]);
- // A = 5, B = 10
- // swap(A, B)
- // A = 10, B = 5
- }
- }
- }
- for(int i = 0; i < N; i += 1) {
- cout << niza[i] << " ";
- }
- return 0;
- }
- /*
- 1 2 3 5 6 7 9
- */
Advertisement
Add Comment
Please, Sign In to add comment