fork download
  1. #include <stdio.h>
  2.  
  3. void swap(int *x, int *y){
  4. int tmp = *x;
  5. *x = *y;
  6. *y = tmp;
  7. }
  8.  
  9. void sort(int *x, int n){
  10. int i, j;
  11. for (i = 1; i < n; i++) {
  12. for (j = 0; j < n - i; j++) {
  13. if (x[j] > x[j+1]) {
  14. swap(&x[j], &x[j+1]);
  15. }
  16. }
  17. }
  18. }
  19.  
  20. int main(){
  21. int x[] = {3,4,2,5,1};
  22.  
  23. sort(x, 5);
  24.  
  25. for(int i=0;i<5;i++){
  26. printf("%d ", x[i]);
  27. }
  28.  
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
1 2 3 4 5