fork download
  1. #include <stdio.h>
  2.  
  3. void sort(int values[], int n){
  4.  
  5. int smallestSpot = 0;
  6.  
  7. for (long long i = 0; i < n ; i++){
  8.  
  9. int smallest = values[i];
  10. smallestSpot = i;
  11.  
  12. for(long long j = i+1; j < n ; j++){ //find the smallest int in array
  13. if(values[j] < smallest){
  14. smallestSpot = j;
  15. smallest = values[j];
  16. }
  17. }
  18.  
  19. values[smallestSpot] = values[i];
  20. values[i] = smallest;
  21. }
  22. }
  23.  
  24.  
  25. int main(void){
  26.  
  27. int arr[5] = {8,1,9,10,2};
  28. sort(arr,5);
  29. for(int i=0;i<5;i++){
  30. printf("%d\n",arr[i]);
  31. }
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0s 4264KB
stdin
Standard input is empty
stdout
1
2
8
9
10