fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n;
  6. cin >> n;
  7.  
  8. int a[1000];
  9.  
  10. for (int i = 0; i < n; i++) {
  11. cin >> a[i];
  12. }
  13.  
  14. for (int i = 0; i < n - 1; i++) {
  15. for (int j = 0; j < n - 1 - i; j++) {
  16.  
  17. if (a[j] > a[j + 1]) {
  18. int temp = a[j];
  19. a[j] = a[j + 1];
  20. a[j + 1] = temp;
  21. }
  22. }
  23. }
  24.  
  25. for (int i = 0; i < n; i++) {
  26. cout << a[i] << " ";
  27. }
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0s 5316KB
stdin
3
3 1 2
stdout
1 2 3