fork download
  1. #define _CRT_SECURE_NO_DEPRECATE
  2. #include <stdio.h>
  3.  
  4. int findLocationOfMin(int a[], int n)
  5. {
  6. int b = 0;
  7. for (int i = 0; i < n; i++)
  8. if (a[i] < a[b])
  9. b = i;
  10. return b;
  11. }
  12.  
  13. int main()
  14. {
  15. int a[1000], m, k, tmp;
  16. scanf("%d %d", &m);
  17. for (int i = 0; i < m; i++)
  18. scanf("%d", &a[i]);
  19. for (int i = 0; i < m; i++)
  20. {
  21. k = findLocationOfMin(a, m);
  22. tmp = a[i];
  23. a[i] = a[k];
  24. a[k] = a[i];
  25. }
  26. for (int i = 0; i < m; i++)
  27. printf("%d ", a[i]);
  28. return 0;
  29. }
Success #stdin #stdout 0s 4476KB
stdin
7
1 2 -3 4 -5 0 6
stdout
-5 -5 -5 -5 -5 -5 -5