fork download
  1. #include <stdio.h>
  2. int main() {
  3. int n;
  4. int arr[n];
  5. printf("enter the number of array elements:");
  6. scanf("%d",&n);
  7. int i, j, pos, swap;
  8. for(int i=0;i<n;i++){
  9. scanf("%d",&arr[i]);
  10. }
  11. for (i = 0; i < (n - 1); i++) {
  12. pos = i;
  13. for (j = i + 1; j < n; j++) {
  14. if (arr[pos] > arr[j])
  15. pos = j;
  16. }
  17. if (pos!= i) {
  18. swap = arr[i];
  19. arr[i] = arr[pos];
  20. arr[pos] = swap;
  21. }
  22. }
  23. for (i = 0; i < n; i++)
  24. printf("%d\t", arr[i]);
  25. return 0;
  26. }
Success #stdin #stdout 0s 5460KB
stdin
45
stdout
enter the number of array elements:0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0	0