fork download
  1. #include <stdio.h>
  2.  
  3. int main() {
  4. int x[] = {25, 57, 48, 37, 12, 92, 86, 33};
  5. int n = sizeof(x) / sizeof(x[0]);
  6. int i, j, minIndex, temp;
  7.  
  8. for (i = n - 1; i > 0; i--) {
  9. minIndex = 0;
  10. for (j = 1; j <= i; j++) {
  11. if (x[j] > x[minIndex]) {
  12. minIndex = j;
  13. }
  14. }
  15. temp = x[i];
  16. x[i] = x[minIndex];
  17. x[minIndex] = temp;
  18. }
  19.  
  20. printf("Sorted array x[]:\n");
  21. for (i = 0; i < n; i++) {
  22. printf("%d ", x[i]);
  23. }
  24.  
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0.01s 5504KB
stdin
Standard input is empty
stdout
Sorted array x[]:
12 25 33 37 48 57 86 92