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